我正在建立一個簡單的菜單,用戶可以從中選擇。出於某種原因,||不工作如果其他C++
else if (letterSelect == "C" || letterSelect = "c")
的||正在出現一個錯誤。另一個||工作正常。錯誤是:沒有運算符「||」匹配這些操作數。操作數類型是; bool ||的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...";
}
letterSelect =「c」應該是letterSelect ==「c」 –