下面是我编写的用于将用户输入的英寸转换为英里、码、英尺的代码。我唯一的问题是我希望输出的格式也需要输出具有“0英寸”。
对于我的生活,我无法弄清楚那么多。我尝试将一个新的 int 值设置为英寸并让它返回 0,但这只会让事情变得更加混乱。
谢谢你的帮助。
#include <iostream>
using namespace std;
int
main ()
{
double m;
double y;
double f;
double i;
cout << " Enter the Length in inches:";
cin >> i;
m = i / 63360; // Convert To Miles
y = 1760 * m; // Convert To Yards
f = 3 * y; // Convert to Feet
i = 12 * f; // Convert to Inches
cout << i << "inches =" << " " << m << " " << "(mile)s," << " " <<
y << " " << "yards," << " " << f << " " << "feet," << " " << i <<
" " << "inches." << endl;
return 0;