我不知道如何得到英寸,它只适用于英尺而不适用于英寸
这是将米转换为英尺再转换为英寸的代码部分
输出示例应该是:
以 double 输入米数:15
15.00 米的值为 49 英尺 2.55 英寸。
//
//METERS_PER_FOOT=0.3048
//INCHES_PER_FOOT=12.0
//makes conversion from metric to English units
void convert(int& feet, double& inches, double meters)
{
feet=meters/METERS_PER_FOOT;
inches=feet/INCHES_PER_FOOT; //this line should give me inches
}
最佳答案
你需要乘而不是除。
有12英寸/英尺。将英尺除以英寸/英尺得到英尺^2/英寸,这有点奇怪。
你的代码应该阅读
inches=feet*INCHES_PER_FOOT;
请注意,您有(米)/(米/英尺)但有(英尺)/(英寸/英尺),这就是为什么一个有效而另一个无效的原因。
关于c++ - 将米转换为英尺到英寸 C++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19921821/