求解加油站小程序
某加油站有’a’、’b’、’c’三种汽油,单价分别为6.12,5.95,5.75(元/千克)。同时,提供“自动加油”、“手工加油”两种服务模式,分别给予2%和5%的优惠。编写程序实现功能:当用户输入加油量、汽油品种和服务类型后,输出应付款。
#include <stdio.h> int main (void) { float a=6.12,b=5.95,c=5.75,amount; char id,mode; //oil id:a,b,c service mode:Y,N printf("Enter number of oil,var of oil,var of service:\n"); scanf("%f %c %c",&amount,&id,&mode); if(mode=='Y') { if(id=='a') { printf ("%.2f\n",amount*a*0.98); } else if(id=='b') { printf ("%.2f\n",amount*b*0.98); } else if(id=='c') { printf ("%.2f\n",amount*c*0.98); } else { printf ("Error!\n"); } } else if(mode=='N') { if(id=='a') { printf ("%.2f\n",amount*a*0.95); } else if(id=='b') { printf ("%.2f\n",amount*b*0.95); } else if(id=='c') { printf ("%.2f\n",amount*c*0.95); } else { printf ("Error!\n"); } } else { printf ("Error !!!\n"); } return 0; }