本帖最后由 yuang4074 于 2015-5-27 09:05 编辑
#include<stdio.h>
int main(){
float price=0,discount=0,pay=0;
char kind='a';float fuel=0; char service='f';
printf("请输入加油量x(x>0),汽油品种y(a/b/c)和服务类型z(f/m/e)\n");
scanf("%f,%c,%c",&fuel,&kind,&service);
printf("您输入的加油量x=%.3f,汽油品种y=%c,服务类型z=%c\n",fuel,kind,service);
switch(service)
{
case 'f': discount= 1;break;
case 'm': discount= 0.05;break;
case 'e': discount= 0.1;break;
default: discount=0;break;
}
switch(kind)
{
case 'a': price= 6.92;break;
case 'b': price= 7.37;break;
case 'c': price= 7.64;break;
default: price=0;break;
}
pay=fuel*price*discount;
if(pay>0)
printf("根据你的选择,你应付款%.2f\n",fuel*price*discount);
else
printf("你选择的汽油量/汽油品种/服务类型不符合条件,请核实....\n");
return 0;
}
|