帝王金大理石价格查询:关于VC的问题,真心的谢谢大家

来源:百度文库 编辑:神马品牌网 时间:2024/05/02 21:39:42
因为在自学C语言,所以很多问题搞不大懂,谢谢大家的帮助,真的

这段代码有问题,但是不知道错哪了,大家帮忙找找好不=.-

#include<stdio.h>
void main()
{
int y; //y为所购商品的单价金额
int x;//x为所购商品的数量
double z; //折扣数
double a; //a为应付金额

printf("请输入所够购商品的单价金额:");
scanf("%d",&y);
printf("请输入够买商品的数量:");
scanf("%d",&x);

if(x<5)
z=0.00;
else if(x>=5 && x<10)
z=0.01;
else if(x>=10 && x<20)
z=0.02;
else if(x>=20 && x<30)
Z=0.04;
else(x>=30)
z=0.06;
a=x*y*(1-z);
printf("应付金额:",a);

}
把printf那里改了以后还是报错=.-

printf("请输入所够购商品的单价金额:");
scanf("%d",&y);
printf("请输入够买商品的数量:");
scanf("%d",&x);
这样写会导致只能读取Y
无法读取X
printf("应付金额:",a); 改成printf("应付金额:%d",a);
如上
a=x*y*(1-z);
应该会出警告

printf("应付金额:",a); 改成printf("应付金额:%d",a);
另外a=x*y*(1-z);中的x和y有可能也要进行强制类型转换

#include<stdio.h>
void main()
{
int y; //y为所购商品的单价金额
int x;//x为所购商品的数量
double z; //折扣数
double a; //a为应付金额

printf("请输入所够购商品的单价金额:");
scanf("%d",&y);
printf("请输入够买商品的数量:");
scanf("%d",&x);

if(x<5)
z=0.00;
else if(x>=5 && x<10)
z=0.01;
else if(x>=10 && x<20)
z=0.02;
else if(x>=20 && x<30)
Z=0.04; //Z大写了
else(x>=30) //应该是else if(x >= 30)
z=0.06;
a=x*y*(1-z);
printf("应付金额:",a); //应该是printf("应付金额:%d",a);

}
----------人如其名