我一直在做這個家庭作業一段時間,準備把我的頭髮拉出來。將十進制舍入到十分之一,但在C++中顯示百分之一
我需要幫助四捨五入到十分之一的位置,同時仍然在百位顯示0,我似乎沒有做任何事情。 即2.47 = 2.50
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float MPH;
float seconds;
const float MPH2MPS = (1609.00/3600.00);
float a;
cout << " Acceleration calculator" << endl;
cout << "" << endl;
cout << "Please enter the velocity in miles per hour: ";
cin >> MPH;
cout << "" << endl;
cout << "Please enter the time in secounds: ";
cin >> seconds;
cout << "" << endl;
cout << "" << endl;
cout << "" << endl;
a = MPH2MPS * (MPH/seconds);
cout << showpoint << fixed << setprecision(2);
cout << "The acceleration required by a vehicle to reach" << endl;
cout << "" << endl;
cout << "a velocity of " << MPH << " miles per hour in " << seconds << " seconds" << endl;
cout << "" << endl;
cout << "is " << setprecision(1) << a << " meters per second" << endl;
cout << "" << endl;
cout << "" << endl;
system("pause");
return 0;
任何想法?
歡迎堆棧溢出。請花時間瀏覽[The Tour](http://stackoverflow.com/tour),並參閱[幫助中心](http://stackoverflow.com/help/asking)上的內容,瞭解什麼和你怎麼能問這裏。發佈[mcve]特別重要。 –
請輸入密碼。並告訴我們您是否想要將變量本身四捨五入或者如果您想圍繞顯示屏。 – Christophe
這裏明顯的選擇是實現你自己的舍入函數.... – xyious