我试图将我的最终答案舍入为2位小数,所以它是美元和美分。我是编码新手,无法弄清楚。我要舍“W”中,说:“你需要充电量”行这里是我的代码:期待围绕2位小数的最终答案C++
#include <iostream>
using namespace std;
int main()
{
string Choice;
float x, w;
cout << "Please enter the amount needed." << endl;
cin >> x;
w = x/(1-0.0275);
cout << "The amount you need to charge is $"<< w << "." << endl;
return (0);
}
http://www.cplusplus.com/forum/beginner/3600/? – 2013-03-03 18:25:26
您无法精确地用浮点数表示大多数小数。使用整数并使用便士来计算。 – 2013-03-03 18:28:03