C++自学新手关于if语句的问题。请各位不吝赐教!

雨夜独行的人 雨夜独行的人 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是一道出自《C++程序设计原理与实践》的习题。

前面的示例程序主要讲了if语句的用法。
我的想法是这样的:
int main()
{
cout << "Please enter the amount and kind of currency: ";
const double jpy_per_usd = 0.0099;
const double eur_per_usd = 1.3519;
const double gbp_per_usd = 1.6274;
double amount;
char kind;
cin >> amount >> kind;
if (kind == 'JPY')
{
cout << amount << " JPY= " << amount*jpy_per_usd << " dollars.\n";
}
else if (kind == 'EUR')
{
cout << amount << " EUR= " << amount* eur_per_usd << " dollars.\n";
}
else
cout << amount << " GBP= " << amount*gbp_per_usd << " dollars.\n";
}

可是当我输入100 JPY或EUR时得出的结果却是这样的:

请问错在哪里?谢谢!
P.s.祝大家马年快乐!
...全文
评论 13
收藏 已收藏
分享
返回顶部
雨夜独行的人
新手乐园 33,314 成员 41,769 内容