代码;
# include <iostream>
# include <windows.h>
using namespace std;
int main () {
int var1 = 1;
int var2 = 1;
bool while1 = true;
int x = 0;
while (x < 999) {
x = x+var1;
x = x+var2;
cout << x << " Is the current value of x, how much would you like to add to it?\n";
Sleep(1000);
while (while1) {
int var3;
cin>> var3;
if (var3 > 100) {
cout << "Too large, between 10 and 100\n";
while1 = true;
}
else if (var3 < 10) {
cout << "Too small, between 10 and 100\n";
while1 = true;
}
else{
cout << "Adding " << var3 << " to " << x << "\n";
x = x + var3;
cout << "x is now " << x << "\n";
while1 = false;
}
}
}
}
现在,问题在于它在第一次循环后完全跳过第二个 while 语句并继续将 var1 和 var2 添加到 x。
这里有什么问题?