厘米到英尺和英寸的转换

Centimeter to feet and inches conversion

本文关键字:转换      更新时间:2023-10-16
#include <cstdio>
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
double cen, inch, feet;
double cen1, feet1;
feet1=cen1/2.54/12;
cin >> cen1;
printf("%.1f",cen1," centimeters is ",double(feet1)," feet ",(float(feet1)-int(feet1)))*12,"      `   inches.";
}
现在,由于

某种原因,由于参数太多且不使用操作数",",我不断收到 printf 部分的错误。我的主要问题是我不知道如何在 printf 中设置东西,以便我可以控制何时删除小数以及剩余多少。提前谢谢。

这不是

printf获取参数的方式。 第一个参数是带有百分比格式代码的格式字符串,然后是格式代码的参数。 它不需要参数列表,它们将它们组合在一起。

您正在寻找的是:

printf("%.1f centimeters is %i feet %.1f inches", cen1, (int)feet1, (feet1-int(feet1))*12);

我使用C++,但是您可能将括号放在错误的位置。尝试:

printf("%.1f",cen1," centimeters is ",double(feet1)," feet ",(float(feet1)-int(feet1))*12,"      `   inches.");

我不确定这是否会解决您的问题,但我相信这是一个可能导致它的错误。