c++ - c++ 如何将 6e(或任何带有 e 的数字)解释为输入?
问题描述
当运行此代码并使用 e 输入 6e 或任何其他数字时,程序无法识别它并最终进入 else 状态。我在这里做错了什么?
#include "../std_lib_facilities.h"
int main() {
cout << "Please enter amount of money followed by the currency name:"
+ "y for yen, p for pound or e for euro, like 3.40e. \n"
<< "This app will convert it to dollars. \n";
double amount;
char currency = ' ';
double dollars;
cin >> amount >> currency;
cout<<"amount: "<< amount <<"\n";
cout<<"currency :" << currency<<"\n";
if (currency == 'y'){
cout <<amount<<"Yuan = "<< amount * 0.15<<" dollars";
}
else if (currency == 'e') {
cout << amount << "Euro = " << amount * 1.18 << " dollars";
}
else if (currency == 'p') {
cout << amount << "Pounds = " << amount * 1.29<< " dollars";
}
else {
dollars = 0;
cout << "Unknown currency\n";
}
}
解决方案
推荐阅读
- vue.js - Vue:如何通过包装组件将值绑定到输入?
- reactjs - 使用钩子多次渲染反应功能组件
- php - 方法 App\Http\Controllers\Elibrary::save 不存在
- stripe-payments - 允许不同的客户为 Stripe 订阅付费
- python - 如何打印实际数据而不是对象的内存位置?
- c# - 在 VS2019 .NET 4.8 中为 C# 项目构建安装程序失败
- javascript - 如何使用javascript从数组中删除键并仅将数据存储在数组中?
- prolog - SWI-prolog 语义推理
- java - 如何将此代码从 switch case 更改为 if else?
- html - 在这两个标签的末尾添加冒号