收到错误消息,提示"运算符=="不匹配。尝试获取if语句以了解用户是否回答"n"然后打印消息



Code是诊断程序,询问y或n个问题,然后使用if语句进行诊断。询问四个是或否问题,如果前两个答案为n,则诊断未知,但如果第一个答案为是,第三个答案为"是",则用户感冒。我还没有打出完整的代码,但所有的问题都显示出来了,第一个if语句返回了一个错误。

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
// variables
string runnyNose;
string congestedNose;
string achyBody;
string severeHeadache;
double bodyTemp;
// Print program name
cout << "==================================" << endl;
cout << "Welcome to Dr. Plympton's Office!" << endl;
cout << "==================================" << endl;

// get runny nose symptom
cout << "Do you have a runny nose (Enter 'y' or 'n')? ";
cin >> runnyNose;
// get congestion symptom
cout << "Are you expeeriencing nasal congestion (Enter 'y' or 'n')? ";
cin >> congestedNose;
// get achy symptom
cout << "Are you feeling achy all over (Enter 'y' or 'n')? ";
cin >> achyBody;
// get headache symptom
cout << "Do you have a severe headache behind or below one eye (Enter 'y' or 'n')? ";
cin >> severeHeadache;
// get temp
cout << "What is your temperature (Enter the number)? ";
cin >> bodyTemp;
if (runnyNose == 'n')
cout << "Unknown: Sorry, you need to see a specialist. Your bill is $40.00. " << 
endl;

return 0;
}

尝试将数据类型从字符串更改为char。您可以将它们与strcmp进行比较,也可以仅与==比较。

最新更新