搜索
查看: 425|回复: 1
打印 上一主题 下一主题

不知道错在哪里,一个英寸转换厘米的程序输出为0

[复制链接]
跳转到指定楼层
楼主
 楼主| 发表于 2018-10-7 11:25:40 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
5啊哈币
本帖最后由 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

最佳答案

查看完整内容

改正如下: #include #include 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; }
沙发
发表于 2018-10-7 11:25:41 | 只看该作者
改正如下:
#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;
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表