问大家一个c语言中关于if问句的问题

我按照书上的内容输进去了,输出窗口却出现了好多没用的数字。。。。
本来是要输数据进去使程序运行的。。。根本输不了。。。。
是不是我少了什么数据类型转换。。。。。
我是个渣什么都不清楚O.o
#include <stdio.h>#include <math.h>void main(){ int number; double cost,price,total; printf("please enter number and price"); printf("%d,%lf",&number,&price); if (number>=500) cost=0.15; else if (number>=300) cost=0.10; else if (number>=100) cost=0.075; else if (number>=50) cost=0.05; else cost=0; total=price*number*(1-cost); printf("total=%10.2f\n",total);}

#include <stdio.h>
#include <math.h>
void main()

int number;
double cost,price,total;
printf("please enter number and price");
scanf("%d,%lf",&number,&price);//是scanf,不是printf,输入的时候记得以逗号分开,不是空格
if (number>=500) cost=0.15;
else if (number>=300) cost=0.10;
else if (number>=100) cost=0.075;
else if (number>=50) cost=0.05;
else cost=0;
total=price*number*(1-cost);
printf("total=%10.2f\n",total);
}

目测,你的结果是因为你的逗号是中文的……

VC++6.0运行结果

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-08-20
那你应该把代码贴出来让大家帮你看看
几个问题啊
首先total初始化一下;
其次c语言输入的时候应该是sprintf,不是printf,所以把你double下面的第二个printf改为sprintf追问

神马是total初始化一下.......T T
还有sprintf书上没出现过.......QAQ

第2个回答  2013-08-20
printf("%d,%lf",&number,&price);应该为scanf("%d,%lf",&number,&price);你没有输入,只是输出追问

改了....新问题在下面.......

追答

我的没问题


#include <stdio.h>

#include <math.h>

void main()

   int number;

   double cost,price,total;

   printf("please enter number and price");

   scanf("%d,%lf",&number,&price);

   if (number>=500) cost=0.15;

   else if (number>=300) cost=0.10;

   else if (number>=100) cost=0.075;

   else if (number>=50) cost=0.05;

   else cost=0;

   total=price*number*(1-cost);

   printf("total=%10.2f\n",total);


   system("pause");

}

结果

因为你的 scanf("%d,%lf",&number,&price);中的%d,%lf之间用的是","逗号,所以输入第一个变量时要用“,”逗号结束,输入第二个变量后再回车,中间不能有回车 或者空格

第3个回答  2013-08-20
第二个应该是scanf啊!!!追问

那也不行啊。。。。得出的结果是负数。。。

追答

你重新编译一下试试 我运行没有问题 

追问

真不行啊T T输好多组数据进去都是出来一串负数。。。。。是不是软件的问题.......

追答

估计是使用了中文符号

第4个回答  2013-08-20
你这个代码根本看不清。。。把代码贴出来啊。。。追问

贴了~
前辈求指导><