gpt4 book ai didi

c++ - 你如何得到一个方程式来输出小数形式的答案?

转载 作者:行者123 更新时间:2023-11-30 02:27:07 25 4
gpt4 key购买 nike

我正在为类作业做作业,我几乎什么都得到了。它只是应该获取盒子的宽度和高度并输出面积以及需要多少油漆。我可以获得前三个部分,但它只会告诉我需要多少油漆,如果它是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com