目前,我的if循环的条件没有得到遵守。无论我为x输入什么,for循环中的语句仍然运行。这里的想法是用户可以输入数据,如果他们想在下一步之前更改数据,他们可以。在while循环结束时,他们应该可以选择跳回到开始,或退出while循环。我最初尝试在while循环中执行while循环,但是根本没有返回任何结果。
int _tmain(int argc, _TCHAR* argv[]) {
dataSet myData;
int a, b, c, d, x, y;
cout << "2 to start, 1 to fail." << endl;
cin >> y >> x;
while (y == 2) {
if (x == 1);
{
cout << "please enter 4 numbers: " << endl;
cin >> a >> b >> c >> d;
int start[4] = { a, b, c, d };
myData.addElements(start);
x = myData.moveForward;
}
myData.beginProcess();
y = myData.moveForward;
x = myData.moveForward;
}
system("pause");
return 0;
}
答案 0 :(得分:2)
您的if
语句不执行任何操作,因为:
if (x == 1);
^~~~ empty statement!
我建议您将警告级别提高到至少/W3
,然后编译器会警告您:
warning C4390: ';' : empty controlled statement found; is this the intent?
答案 1 :(得分:0)
应该没有;在if语句之后
答案 2 :(得分:0)
if (x == 1);
if (x == 1)
将执行下一条指令。这只是;
,“无效”指令。
之后,if
块已经结束并继续执行下一个代码(您认为只有在x == 1
时才执行的嵌套块)