C++ 带有OR运算符的if语句
我正在Visual Studio 2013上编写此代码 当我通过回答第一个问题(1)来执行代码时,程序仍然会问我第二个问题 如果我回答第一个问题(1),程序不应该跳过第二个问题吗C++ 带有OR运算符的if语句,c++,if-statement,operators,C++,If Statement,Operators,我正在Visual Studio 2013上编写此代码 当我通过回答第一个问题(1)来执行代码时,程序仍然会问我第二个问题 如果我回答第一个问题(1),程序不应该跳过第二个问题吗 #include <iostream> using namespace std; int main() { cout << "Answer questions with 0 or 1" << endl; cout << "Is there a deep
#include <iostream>
using namespace std;
int main()
{
cout << "Answer questions with 0 or 1" << endl;
cout << "Is there a deep discount on your favorite car? ";
bool Discount = false;
cin >> Discount;
cout << "Did you get a fantastic bonus? ";
bool FantasticBonus = false;
cin >> FantasticBonus;
if (Discount || FantasticBonus)
cout << "Congratulations, you can buy that car!" << endl;
else
cout << "Sorry, waiting a while is a good idea" << endl;
return 0;
}
#包括
使用名称空间std;
int main()
{
花红;
if(折扣| |奖金)
cout不会跳过第二个问题,因为在第一个答案后的第二个问题之前没有条件。如果在第一个答案输入1时要跳过第二个问题:
bool FantasticBonus = false;
if(!Discount) {
cout << "Did you get a fantastic bonus? ";
cin >> FantasticBonus;
}
bool fantaticbonus=false;
如果(!折扣){
cout>幻想奖金;
}
为什么要这样做?你的程序会问一个问题,然后另一个问题会输出一条或另一条消息。如果你想做什么,那么你必须对它进行编码。