【发布时间】:2023-04-11 03:59:01
【问题描述】:
{
cout << "type 3 to add ,type 1 to multiply,type division to divide,type 2 to subtract" << endl;
cin >> function;
if (function == 1)
{
multiply();
}
else if (function == 2)
{
subtract();
}
else if (function == 3)
{
add();
}
else if (function == 4)
{
division();
}
cout << "press x to quit or anything else to restart " << endl;
cin >> input;
} while (input !='x');
system("pause");
return 0;
}
在此代码中,我无法使用 if
例如,如果(function=='add') 它不起作用
如果我使用if(function='add'),里面的所有东西都会跳到最后一个cout,上面写着
按 x 退出或其他任何东西重新启动
【问题讨论】:
-
函数在哪里定义?它是一个字符吗?一个整数?见stackoverflow.com/help/mcve
-
什么是
function? -
function='add' 不在您的条件范围内,因此您不会觉得它会跳过所有条件
-
@Detonar:不是真的:它实际上是一个多字符文字。
-
请提供Minimal, Complete, and Verifiable 示例。将变量命名为
function具有误导性。
标签: c++ loops while-loop character