啊哈磊_编程从这里起步

标题: 不知道错在哪里,一个英寸转换厘米的程序输出为0 [打印本页]

作者: MagicLee    时间: 2018-10-7 11:25
标题: 不知道错在哪里,一个英寸转换厘米的程序输出为0
本帖最后由 MagicLee 于 2018-10-7 12:21 编辑

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int inch;    float centimeter;
    printf("please enter inch.\n");
    scanf("%d", &inch);
    inch = centimeter * 2.54;
    printf("The inches you enter are equal to %.2f centimeters");
    system("pause");
    return 0;
}
输出结果是-1.#R这种乱码值,是不是声明类型,转换说明没用对啊?


5TTC3~YX~}D`RN7(J[{X0]7.png (174.3 KB, 下载次数: 2)

5TTC3~YX~}D`RN7(J[{X0]7.png

作者: 彩虹兔兔    时间: 2018-10-7 11:25
改正如下:
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int inch;    float centimeter;
    printf("please enter inch.\n");
    scanf("%d", &inch);
    centimeter = inch * 2.54; //写反了没发现吧,哈哈,看清要干什么啊
    printf("The inches you enter are equal to %.2f centimeters",centimeter);//后面没有加要放进去的变量啊,忘了吧
    system("pause");
    return 0;
}





欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2