-5
我是初學者。我希望爲我的計算機科學提供一些幫助,因爲它失敗了,我不明白爲什麼setprecision在這裏不起作用,但在我製作的其他程序中工作得很好?我明白這段代碼並不完整,但對我來說沒有意義。十進制值不起作用? (C++)
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int sug = 1.5;
int but = 1;
int flo = 2.75;
int tel = 48;
double ans;
cout << "How much cookies would you like to make? ";
cin >> ans;
cout << setprecision(2) << fixed << showpoint << "For " << tel << " amount of cookies, you need " << flo << endl;
return 0;
}
指定小數時使用'float'而不是'int' –
您的代碼[不起作用](http://importblogkit.com/2015/07/doe S-不工作/)? –
你認爲'2.75'是一個整數,所以它被評估爲'2'。或'3'。無論如何,實際上,因爲無論如何,這並不合乎邏輯。 –