作者在 2020-11-19 21:51:58 发布以下内容
#include <stdio.h>
#define pyj 2.05 /* 洋蓟:2.05美元/磅 */
#define ptc 1.15 /* 甜菜:1.15美元/磅 */
#define phlb 1.09 /*胡萝卜:1.09美元/磅 */
#define b100d 100 /*100美元订单有5%的优惠*/
#define yhu 0.05 /*100美元订单有5%的优惠*/
#define b5b 5 /*5磅以内收取6.5美元的运费和包装费*/
#define yubf0 6.5 /*5磅以内收取6.5美元的运费和包装费*/
#define b20b 20 /*5-20磅收取14美元的运费和包装费*/
#define yubf1 14 /*5-20磅收取14美元的运费和包装费*/
#define xzh 1 /*续重1磅增加0.5美元*/
#define xzhf 0.5 /*续重1磅增加0.5美元*/
void menu(void);
void star(int i);
double single(double doll,double base);
int main(void)
{
char ch;
double base1,weight=0.0;
double zzha=0.0,zzhb=0.0,zzhc=0.0,zzh=0.0;
double zyj=0.0,ztc=0.0,zhlb=0.0,gongji=0.0;
double basea=0.0,baseb=0.0,basec=0.0;
double yhui=0.0,bzf=0.0;
int i=0;
do{
menu();
if(i==0)printf("\n想买啥:");else printf("\n还想买啥?");
scanf(" %c",&ch);
i++;
switch(ch)
{
case 'a':basea=pyj;break;
case 'b':baseb=ptc;break;
case 'c':basec=phlb;break;
case 'q':break;
default:printf("\nSORRY,没有这种菜,选点别的吧.\n\n");
//getchar();
//scanf(" %c",&ch);
}
if(ch=='a'||ch=='b'||ch=='c')
{
printf("想买几磅:");
scanf("%lf",&weight);
if(ch=='a')zzha+=weight;
if(ch=='b')zzhb+=weight;
if(ch=='c')zzhc+=weight;
//if (ch=='a') cmin[20]="yangji";
zyj=single(zzha,basea);ztc=single(zzhb,baseb);zhlb=single(zzhc,basec);
if(zzha>0)printf("\n您购买了洋蓟总共 %.2f 磅,洋蓟小计为:%.2f 美元。",zzha,zyj);
if(zzhb>0)printf("\n您购买了甜菜总共 %.2f 磅,甜菜小计为:%.2f 美元。",zzhb,ztc);
if(zzhc>0)printf("\n您购买了胡萝卜总共 %.2f 磅,胡萝卜小计为:%.2f 美元。",zzhc,zhlb);
zzh=zzha+zzhb+zzhc;
gongji=zyj+ztc+zhlb;
printf("\n您总共买了%.2f美元的菜,总重为%.2f磅。\n\n\n",gongji,zzh);
}}while(ch!='q');
if(gongji>=b100d)yhui=gongji*yhu;
if(zzh<=b5b)bzf=yubf0;
else if(zzh<=b20b)bzf=yubf1;
else bzf=yubf1+(zzh-b20b)/xzh*xzhf;
printf("\n菜价总计:%.2f 美元.\n优惠:%.2f 美元\n\n菜价应付总额:%.2f 美元。" ,gongji,yhui,gongji-yhui);
printf("\n运费及包装费为:%.2f 美元.\n",bzf );
printf("\n应付费用总计:%.2f 美元。",bzf+gongji-yhui);
printf("\n\n\n*****谢谢惠顾*****\n\n\n");
return 0;
}
double single(double doll,double base)
{
return doll*base;
{
star(70);
printf("\n");
printf("\t\t\tABC邮购杂货店\n\n");
printf("a) 洋蓟-$2.05/磅\t\t\tb) 甜菜-$1.15/磅");
printf("\nc) 胡萝卜-$1.09/磅\t\t\tq) 不买了");
printf("\n");
star(70);
}
void star(int i)
{
for(int j=0;j<i;j++)
{
printf("*");
}
//printf("\n");
}
#define pyj 2.05 /* 洋蓟:2.05美元/磅 */
#define ptc 1.15 /* 甜菜:1.15美元/磅 */
#define phlb 1.09 /*胡萝卜:1.09美元/磅 */
#define b100d 100 /*100美元订单有5%的优惠*/
#define yhu 0.05 /*100美元订单有5%的优惠*/
#define b5b 5 /*5磅以内收取6.5美元的运费和包装费*/
#define yubf0 6.5 /*5磅以内收取6.5美元的运费和包装费*/
#define b20b 20 /*5-20磅收取14美元的运费和包装费*/
#define yubf1 14 /*5-20磅收取14美元的运费和包装费*/
#define xzh 1 /*续重1磅增加0.5美元*/
#define xzhf 0.5 /*续重1磅增加0.5美元*/
void menu(void);
void star(int i);
double single(double doll,double base);
int main(void)
{
char ch;
double base1,weight=0.0;
double zzha=0.0,zzhb=0.0,zzhc=0.0,zzh=0.0;
double zyj=0.0,ztc=0.0,zhlb=0.0,gongji=0.0;
double basea=0.0,baseb=0.0,basec=0.0;
double yhui=0.0,bzf=0.0;
int i=0;
do{
menu();
if(i==0)printf("\n想买啥:");else printf("\n还想买啥?");
scanf(" %c",&ch);
i++;
switch(ch)
{
case 'a':basea=pyj;break;
case 'b':baseb=ptc;break;
case 'c':basec=phlb;break;
case 'q':break;
default:printf("\nSORRY,没有这种菜,选点别的吧.\n\n");
//getchar();
//scanf(" %c",&ch);
}
if(ch=='a'||ch=='b'||ch=='c')
{
printf("想买几磅:");
scanf("%lf",&weight);
if(ch=='a')zzha+=weight;
if(ch=='b')zzhb+=weight;
if(ch=='c')zzhc+=weight;
//if (ch=='a') cmin[20]="yangji";
zyj=single(zzha,basea);ztc=single(zzhb,baseb);zhlb=single(zzhc,basec);
if(zzha>0)printf("\n您购买了洋蓟总共 %.2f 磅,洋蓟小计为:%.2f 美元。",zzha,zyj);
if(zzhb>0)printf("\n您购买了甜菜总共 %.2f 磅,甜菜小计为:%.2f 美元。",zzhb,ztc);
if(zzhc>0)printf("\n您购买了胡萝卜总共 %.2f 磅,胡萝卜小计为:%.2f 美元。",zzhc,zhlb);
zzh=zzha+zzhb+zzhc;
gongji=zyj+ztc+zhlb;
printf("\n您总共买了%.2f美元的菜,总重为%.2f磅。\n\n\n",gongji,zzh);
}}while(ch!='q');
if(gongji>=b100d)yhui=gongji*yhu;
if(zzh<=b5b)bzf=yubf0;
else if(zzh<=b20b)bzf=yubf1;
else bzf=yubf1+(zzh-b20b)/xzh*xzhf;
printf("\n菜价总计:%.2f 美元.\n优惠:%.2f 美元\n\n菜价应付总额:%.2f 美元。" ,gongji,yhui,gongji-yhui);
printf("\n运费及包装费为:%.2f 美元.\n",bzf );
printf("\n应付费用总计:%.2f 美元。",bzf+gongji-yhui);
printf("\n\n\n*****谢谢惠顾*****\n\n\n");
return 0;
}
double single(double doll,double base)
{
return doll*base;
}
{
star(70);
printf("\n");
printf("\t\t\tABC邮购杂货店\n\n");
printf("a) 洋蓟-$2.05/磅\t\t\tb) 甜菜-$1.15/磅");
printf("\nc) 胡萝卜-$1.09/磅\t\t\tq) 不买了");
printf("\n");
star(70);
}
void star(int i)
{
for(int j=0;j<i;j++)
{
printf("*");
}
//printf("\n");
}