c++ - 如何解决这个“'.'之前的预期主表达式'。JarOfJam 部分的令牌?
问题描述
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <windows.h>
using namespace std;
struct jam{
double mass;
};
double calculation (double weight){
double sugar,Wtotal,Stotal;
string Atable[3]={"Mass of strawberry:","Mass of sugar:","Mass of jam:"};
int Btable[3];
Btable[0]=weight;
Btable[1]=sugar=(weight*55)/45;
Wtotal=(weight*0.85);
Btable[2]=Stotal=Wtotal+(weight*0.15)+weight;
for(int count=0; count<3; count++)
cout<<Atable[count]<<Btable[count]<<endl;
}
int Functionable (double weight){
double sugar=(weight*55)/45;
double Wtotal=(weight*0.85);
double Stotal=Wtotal+(weight*0.15)+weight;
if(Stotal<=1000){
cout<<"The machine is avaliable to function."<<endl;}
else{
Beep(1568, 200);
Beep(1568, 200);
Beep(1568, 200);
Beep(1245, 1000);
Beep(1397, 200);
Beep(1397, 200);
Beep(1397, 200);
Beep(1175, 1000);
cout<<"The machine is unavaliable to function. Enter to restart."<<endl;
restart(0);
}
}
double JarOfJam ( struct jam,double weight)
{
double sugar=(weight*55)/45;
double Wtotal=(weight*0.85);
double Stotal=Wtotal+(weight*0.15)+weight;
double Jar=Stotal/jam.mass;
}
int main(){
double mass;
jam num;
char choice;
choice='p','P','f','F','q','Q';
cout<<"This is a program for calculation of ";
cout<<"the required mass of sugar and ";
cout<<"the mass of the strawberry jam."<<endl;
cout<<"Enter f to understand the calculation."<<endl;
cout<<"Enter p to proceed to calculation."<<endl;
cout<<"Enter q to exit the program."<<endl;
cout<<"Your choice:";
cin>>choice;
if(choice=='q'||choice=='Q'){
exit(0);
}
if (choice=='f'||choice=='F'){
cout<<"File name: Calculation."<<endl;
}
if (choice=='p'||choice=='P'){{
cout<<"Please enter the mass of the strawberry you have bought."<<endl;
cin>>mass;
cout<<"Result:"<<endl;
calculation(mass);
Functionable(mass);
cout<<"Enter p to start the machine, q to exit the program."<<endl;
cin>>choice;
}
if (choice=='p'||choice=='P'){
cout<<"The machine start processing the strawberry jam."<<endl;
cout<<"Enter the amount of strawberry jam per jar."<<endl;
cin>>num.mass;
cout<<"The number of jar could be produced is ";
}
else{
exit(0);
}
}
return 0;
}
这是我大学里的一个小项目
解决方案
在 C++ 中,结构会自动声明为类型。
问题在这里:
double JarOfJam ( struct jam,double weight)
^^^^^^^
只需使用声明的结构的名称作为第一个参数的类型:
double JarOfJam (jam jamInstance, double weight)
并且不要忘记将函数的其余部分更改为引用“jamInstance”。
推荐阅读
- javascript - 如何按数组字段值javascript对数组进行排序
- linux - 无法在 Debian 上安装 Telegram:ModuleNotFoundError: No module named 'apt_pkg'
- swift - 为什么 Apple 创建 isBatteryMonitoringEnabled?
- regex - 如何使用可选组作为以下首选 java 语法使用正则表达式解析文本
- c# - PrincipalContext.ValidateCredentials 方法中的“有效”含义是什么?
- android - 安卓SDK在哪里下载?
- javascript - 凭证可以在js文件Dev Tool中看到
- keras - 每次运行代码时,Google Colab Runtime 都会死掉
- android - 找不到模块:错误:无法解析“nativescript-sound”
- angular - 如何使用angular4将选定的选项值发布到角度材料表