c++ - 如何解决:没有运算符匹配这些操作数
解决方案
您的错误是因为您试图将 aint
与 a进行比较string
,这是行不通的,该比较未定义。此外,string
无论如何,你的都是空的。
另外,您的结尾if
有错误;
。事实上,你的整体if
毫无意义,应该被删除。
试试这个:
#inslude <iostream>
using namespace std;
int main()
{
int TDU, kWh;
cout << "Who is your TDU?\n";
cin >> TDU;
cout << "How many kWh did you use for the month you would like to calculate?\n";
cin >> kWh;
cout << "Your bill is " << 3.42 + (0.0384470 * kWh);
return 0;
}
更新:话虽这么说,你可能打算做更多这样的事情:
#inslude <iostream>
using namespace std;
static const int ONCOR = ...; // <-- for you to fill in as needed...
int main()
{
int TDU, kWh;
cout << "Who is your TDU?\n";
cin >> TDU;
cout << "How many kWh did you use for the month you would like to calculate?\n";
cin >> kWh;
if (TDU == ONCOR)
cout << "Your bill is " << 3.42 + (0.0384470 * kWh);
return 0;
}
或者:
#inslude <iostream>
using namespace std;
int main()
{
string TDU;
int kWh;
cout << "Who is your TDU?\n";
cin >> TDU;
cout << "How many kWh did you use for the month you would like to calculate?\n";
cin >> kWh;
if (TDU == "ONCOR")
cout << "Your bill is " << 3.42 + (0.0384470 * kWh);
return 0;
}
取决于您希望用户输入的格式TDU
。
推荐阅读
- r - 如何在 R 中使用带有 url 的代理?
- jenkins - 在 Jenkins Post-build 中使用 ANT 构建中的变量
- javascript - 如何为 dialogflow v2 REST API 验证客户端
- r - 用点传递函数参数
- javascript - 如何使用 python json 渲染模板作为树视图?
- python - 如何为使用的 EventStream 创建一个模拟,但 S3 Select API 用于基于 S3 Select 查询获取内容?
- java - 当 Rserve 启用 TLS 时,Java Rconnection 挂起
- windows - Windows 10 使用什么 Mechanisum 来检测程序中的相似性以在任务栏上对它们进行分组
- python - 代码在网站上找不到任何产品
- r - 在文本文件文件夹上使用带有换行符的正则表达式进行替换