我正在构建一个用户可以选择的简单菜单。出于某种原因
else if (letterSelect == "C" || letterSelect = "c")
||出现错误。另一个||工作得很好。错误是:没有运算符“||”匹配这些操作数。操作数类型是;布尔||的std :: string
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
cout << "********* General Purpose Calculator Program ***************\n"
<< "Please Select an Option by inputting its associated letter\n"
<< "A) Determine Highest of Three Numbers\n"
<< "B) Reverse a Number\n"
<< "C)Calculate Parking Garage Charges\n"
<< "D) Exit\n";
string letterSelect = " ";
cin >> letterSelect;
if (letterSelect == "A" || letterSelect == "a")
{
//call program listed for A;
}
else if (letterSelect == "B" || letterSelect == "b")
{
//call program listed for B;
}
else if (letterSelect == "C" || letterSelect = "c")
{
//call program listed for C;
}
else (letterSelect == "D" || letterSelect == "d");
cout << "Exiting...";
}
答案 0 :(得分:1)
下面:
else if (letterSelect == "C" || letterSelect = "c")
您在第二部分条件中缺少=
。
它应该是letterSelect == "c"
答案 1 :(得分:1)
只是一个错字。 '||'的右侧在您的代码中是赋值(=),而不是相等检查(==)。
答案 2 :(得分:1)
代码行
letterSelect = "c"
是分配操作而不是比较。将其更改为
letterSelect == "c"
它应该有用。
快乐的编码。