gpt4 book ai didi

c++ - 丢失的 ;在标识符 cout 之前

转载 作者:行者123 更新时间:2023-11-27 22:55:56 25 4
gpt4 key购买 nike

我正在完成我的学校项目。我写了所有内容,但似乎有错误:

missing ";" before cout at line 15 before " your number is bigger than..."

我无法理解或修复此错误。请帮忙。整个程序的代码如下:

#include <iostream>
using namespace std;

int main()
{
int intSecretNum = 47;
int intGuess;
cout<< "Guess the secret number (between 0 and 100 inclusively): ";
cin>> intGuess;
while(intSecretNum != 47, intGuess<= 5)
{
if( intGuess < intSecretNum)
cout << "Your Number is smaller than the secret number";
else (intGuess > intSecretNum)
cout << "Your Number is bigger than the secret number";
intGuess++;
if(intGuess>5)
cout << "Sorry, you have used up all your quota (5 times)! The secret number is "<<intSecretNum;
cout << "program terminated." <<endl;
}
cout<< "You have used "<<intGuess <<"to guess te secret number which is " <<intSecretNum<<".";
cout<<"program terminated."<<endl;
return 0;
}

我对这个 C++ 很陌生,请帮忙

最佳答案

你的问题在这里

else (intGuess > intSecretNum)
cout << "Your Number is bigger than the secret number";

这假设 (intGuess > intSecretNum) 是一个将在 else 条件下执行的语句,这就是为什么您收到错误警告您缺少分号的原因.

相反你应该有

else if(intGuess > intSecretNum)
cout << "Your Number is bigger than the secret number";

关于c++ - 丢失的 ;在标识符 cout 之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33135593/

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