我的程序可以很好地将英尺和英寸转换为米,但它总是会在米和英尺和英寸转换上添加随机数的英尺。我不知道为什么。任何建议将不胜感激。
EX)指出1.3208026m等于4ft 4in时等于8ft 4in。
#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;
}
最佳答案
第一次转换后,您需要将英尺重置为零。