gpt4 book ai didi

C++ 预期主表达式在 ';' 标记之前

转载 作者:太空宇宙 更新时间:2023-11-04 15:14:57 25 4
gpt4 key购买 nike

我收到一条错误消息,指出“expected primary-expression ';' token”,它突出显示了我的百分比公式。我试图重新排列我的代码,但似乎问题不在其中。

const int TOTALSUITES = 120;

for (int floor = 10; floor <= 16; floor++) {
if ( floor != 13) {
do {
cout << "Please enter the number of suites occupied on the floor " << floor << ":";
cin >> numOccupied;

if ((numOccupied <0) || (numOccupied >20 )) {
goodChoice = false;
cout << "\n\t\t**ERROR" << numOccupied << " ***\n\n";
cout << "*** Choice must be from [0-20]***\n";
}
else {
goodChoice = true;
}
totalOccupied += numOccupied;
} while (!goodChoice);
}
}

percentage = (totalOccupied / TOTALSUITES) * 100% ;
cout << endl;
cout << "Hotel has " << TOTALSUITES << endl;
cout << "Number of occupied suites is " << totalOccupied << endl;
cout << "The percentage of occupied suites is " << percentage << endl;
system("pause");
return 0;

最佳答案

% 这里使用的是模运算符,它是一个二元运算符...所以这就是你必须做的......

percentage = (totalOccupied / TOTALSUITES)* 100;

//然后在那个时候你有 cout percentage 的地方...做这个

cout<<"the percentage of occupied suites is"<<percentage<<"%";

关于C++ 预期主表达式在 ';' 标记之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35898426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com