我的程序可以很好地将英尺和英寸转换为米,但它总是会在仪表上添加一个随机数量的英尺到英尺和英寸的转换。我无法弄清楚为什么。任何建议将不胜感激。 EX)它表示1.3208026m等于8英尺4英寸,实际上是4英尺4英寸。
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;
int feet;
double meters, inches;
int main()
{
cout << "Enter feet " << endl;
cin >> feet;
cout << "Enter inches " << endl;
cin >> inches;
inches = feet * 12 + inches;
meters = inches / 39.370;
cout << setprecision(8) << meters << "m" << endl << endl;
cout << "Enter meters. " << endl;
cin >> meters;
inches = meters * 39.37;
while (inches > 12)
{
if (inches > 12)
inches = inches - 12;
feet++;
}
cout << feet << " ft and " << setprecision(8) << inches << "in" << endl;
return 0;
}
答案 0 :(得分:1)
首次转换后,您需要将脚重置为零。
答案 1 :(得分:0)
if (inches > 12)
inches = inches - 12;
feet++;
没有。需要牙套,否则你的脚就会失败。