为什么我的浮点数打印为0,即使我使用scanf输入13.5?

为什么我的浮点数打印为0,即使我使用scanf输入13.5?,第1张

概述我无法弄清楚为什么我的浮点变量在输入数字时保持打印输出为0. 码: int num, month, day, year;float price[10000];printf("Enter item number: \n");scanf("%d", &num);printf("Enter unit price: \n");scanf("%f", &price);printf("Ente 我无法弄清楚为什么我的浮点变量在输入数字时保持打印输出为0.

码:

int num,month,day,year;float price[10000];printf("Enter item number: \n");scanf("%d",&num);printf("Enter unit price: \n");scanf("%f",&price);printf("Enter purchase date (mm/dd/yyyy): \n");scanf("%d/%d/%d",&month,&day,&year);printf("Item\t\tUnit\t\tPurchase\n");printf("    \t\tPrice\t\tDate\n");printf("%d      ",num);printf("$%.2f     ",price); printf("      %d/%d/%d\n",year);return 0;

我为我的商品编号输入555,为我的价格输入13.5,为我的日期输入10/24/2010.
当我这样做时打印出我的价格是0.00美元.它为我输入的任何数字执行此 *** 作.为什么?

解决方法 只需改变这个:
float price[10000];

对此:

float price;

因为您将它用作单个变量而不是数组

总结

以上是内存溢出为你收集整理的为什么我的浮点数打印为0,即使我使用scanf输入13.5?全部内容,希望文章能够帮你解决为什么我的浮点数打印为0,即使我使用scanf输入13.5?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1257047.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存