我試圖將我的最終答案舍入爲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