[英]loops are not continuing can't figure out why
嘿,我這里有這個程序
#include <iostream>
using namespace std;
int main()
{
int MyNum;
int ComNum;
MyNum = 5;
do {
cout << "Enter a whole number between 1 and 10: ";
cin >> ComNum;
if (ComNum > MyNum) {
cout << "Sorry that is incorrect (Hint: too high)";
}
if (ComNum < MyNum) {
cout << "Sorry that is incorrect (Hint: too low)";
cin >> ComNum;
}
} while(MyNum != ComNum);
cout << "Correct"
}
我不知道為什么在第一個錯誤答案后它不會繼續運行我確定我遺漏了一些小而愚蠢的東西(PS)這是一個猜測我的數字游戲,如果你不能從代碼中分辨出來
缺少分號在正確后給出錯誤:
#include <iostream>
using namespace std;
int main()
{
int MyNum;
int ComNum;
MyNum = 5;
do {
cout << "Enter a whole number between 1 and 10: ";
cin >> ComNum;
if (ComNum > MyNum) {
cout << "Sorry that is incorrect (Hint: too high)";
}
if (ComNum < MyNum) {
cout << "Sorry that is incorrect (Hint: too low)";
cin >> ComNum;
}
} while(MyNum != ComNum);
cout << "Correct";
}
正如其他人所說,第二個 cin >> ComNum; 是不必要的,雖然它在https://www.onlinegdb.com/online_c++_compiler上工作
只需刪除cin >> ComNum;
在 IF 中並修復編譯器錯誤cout << "Correct";
.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.