#include "stdafx.h"
#include
#define Sever_type 3
#define Oil_type 4
int oil_type;
int serve_type;
double ALL_Price;
struct OIL
{
char *type;
double price;
};
struct SERVES
{
char *type;
double reduce;
};
OIL oil[4]={
{"90号汽油",6.95},
{"93号汽油",7.44},
{"97号汽油",7.93},
{"o错误",0.00},};
SERVES serve[3]={
{"m - 自助",0.05},
{"e - 协助",0.03},
{"s错误",0.00},};
void Prinf_Oil_message()
{
for(int i=0;i { printf("%s: 价格是%.2f \n",oil[i].type,oil[i].price); } for(int j=0;j { printf("%s: 优惠%.2f \n",serve[j].type,serve[j].reduce); } }; void Choice_serve_Oil(int ml,char S_type,int O_type) { int current_ml=ml; switch(S_type) { case 'm' : serve_type=0; break; /* 可选的 */ case 'e' : serve_type=1; break; /* 可选的 */ /* 您可以有任意数量的 case 语句 */ default : serve_type=2; printf("ERROR %s:PLS input again\n",serve[serve_type].type); /* 可选的/* 可选的 */break; } switch(O_type) { case 90 : oil_type=0; break; /* 可选的 */ case 93 : oil_type=1; break; /* 可选的 */ case 97 : oil_type=2; break; /* 可选的 */ /* 您可以有任意数量的 case 语句 */ default : oil_type=3; printf("ERROR %s:PLS input again\n",oil[oil_type].type); /* 可选的 */break; } if(serve_type!=2&&oil_type!=3) { ALL_Price=current_ml*(1-serve[serve_type].reduce)*oil[oil_type].price; printf("你的服务: %s,油: %s\n",serve[serve_type].type,oil[oil_type].type); printf("总价格为%.2f,Welcome\n",ALL_Price); } }; int main(int argc, char* argv[]) { int weight_kg=0; char seversult; int oilresult=0; Prinf_Oil_message(); printf("Welcome Oilstation,Pls choice serves:\n"); while(true) { printf("PLS input: 重量(kg),服务(m or e),油型(90,93,97)\n"); scanf("%d,%c,%d",&weight_kg,&seversult,&oilresult); Choice_serve_Oil(weight_kg,seversult,oilresult); } return 0; }
int main()
{
int a,b;
char c;
scanf("%d,%d,%c",&a,&b,&c);
float price;
float cost;
switch(b)
{
case 90:
price = 6.95;
break;
case 93:
price =7.44;
break;
case 97:
price = 7.93;
break;
default:
printf("无效汽油品种");
return 0;
}
if(c == 'm')
{
cost = price * a * 0.95;
}
else if(c == 'e')
{
cost = price * a * 0.97;
}
else
{
printf("错误服务类型");
return 0;
}
printf("%.2f\n",cost);
return 0;
}
我按照要求来搞定。