anewcomer356 2022-09-20 16:59 采纳率: 100%
浏览 8
已结题

scanf函数的输出问题


#include <stdio.h>
int main(void)
{
    float weight,value;
    //假设白金的价格为每(金衡)盎司¥1700,单位换算机制详见P34
    value=1700*weight*14.5833;
 
    printf("Are you worth you weight in platinum?\n");
    printf("let's check it out.\n");
    printf("Please enter your weight in pounds.\n");
 
    //新函数scanf:用于获取用户输入
    getchar();
    scanf_s("%f",&weight);
    getchar();
    printf("So your weight in platinum is worth $%.2f.\n",value);
    printf("You are easily worth that! If platinum prices drop,\n");
    printf("eat more to maintain your value.\n");
 
    return 0;
}

第16行代码中value的值无法赋到转换说明处,显示结果仍为0.00

  • 写回答

2条回答 默认 最新

  • 快乐鹦鹉 2022-09-20 17:01
    关注

    14行为啥要getchar()
    你输入的是weight,但输出的是value.
    你应该将15行放到第6行,先输入再计算啊

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月28日
  • 已采纳回答 9月20日
  • 创建了问题 9月20日