gpt4 book ai didi

c++ - 如果条件被忽略

转载 作者:行者123 更新时间:2023-11-28 02:15:10 25 4
gpt4 key购买 nike

目前,我的 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;
}

最佳答案

您的 if 语句什么都不做,因为:

if (x == 1);
^~~~ empty statement!

我建议您将警告级别至少提高到 /W3,这样编译器就会警告您:

warning C4390: ';' : empty controlled statement found; is this the intent?

关于c++ - 如果条件被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34246853/

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