首页 > 解决方案 > 如何解决这个“'.'之前的预期主表达式'。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++

解决方案


在 C++ 中,结构会自动声明为类型。

问题在这里:

double JarOfJam ( struct jam,double weight)
                  ^^^^^^^

只需使用声明的结构的名称作为第一个参数的类型:

double JarOfJam (jam jamInstance, double weight)

并且不要忘记将函数的其余部分更改为引用“jamInstance”。


推荐阅读