我正在为类作业做作业,我几乎什么都得到了。它只是应该获取盒子的宽度和高度并输出面积以及需要多少油漆。我可以获得前三个部分,但它只会告诉我需要多少油漆,如果它是 400 的倍数(用于确定需要多少油漆的数字)。
我目前有这个:
#include <iostream>
using namespace std;
int main()
{
int wallHeight, wallWidth, wallArea;
cout << "Please enter the height of the wall (feet): ";
cin >> wallHeight;
cout << endl << "Please enter the width of the wall (feet): ";
cin >> wallWidth;
wallArea = wallHeight * wallWidth;
const double paintNeeded = wallArea / 400;
cout << endl << "The area of the wall is: " << wallArea << " square feet. "
<< "This will require about " << paintNeeded << " gallons of paint." << endl;
return 0;
}
假设我输入的是 24x2 的墙。它会说面积是 48,但它需要 0 加仑的油漆,我只想说它需要 0.12 加仑。
感谢您的帮助。
最佳答案
将 wallArea
转换为 double:
const double paintNeeded = (double)wallArea / 400;
关于c++ - 你如何得到一个方程式来输出小数形式的答案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42101361/