我的 if 语句贯穿始终,就好像条件已满足,即使条件尚未满足。我尝试过移动一些代码,甚至以不同的方式重写 if 语句,但它并没有改变结果。有谁知道我做错了什么?
#include <iostream>
#include <string>
using namespace std;
double num, num2, num3, num4, num5, num6, sum;
char input;
bool continueBool = true;
string bob;
void math()
{
cout << "Please enter your first number" << endl;
cin >> num;
cout << "Please enter your second number?" << endl;
cin >> num2;
cout << "Please enter your third number?" << endl;
cin >> num3;
cout << "Please enter your fourth number" << endl;
cin >> num4;
cout << "Please enter your fith number?" << endl;
cin >> num5;
cout << "Please enter your sixth number?" << endl;
cin >> num6;
sum = num + num2 + num3 + num4 + num5 + num6;
}
void ifStatement() {
if (bob == "no", "No", "NO", "nO") {
continueBool = false;
cout << "Good bye!" << endl;
}
}
int main()
{
while (continueBool = true) {
math();
cout << "The sum of your numbers is: " << sum << endl;
cout << "Would you like to add any more numbers together?" << endl;
cin >> bob;
ifStatement();
return 0;
}
}
这确实是假的
if (bob == "no", "No", "NO", "nO")
你需要用逻辑或来打破它
if (bob == "no" || bob == "No" || bob == "NO" || bob == "nO")
就目前情况而言,这if (bob == "no", "No", "NO", "nO")
将相当于if("nO")
作为逗号运算符的效果。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)