C语言ABC Mail Order Grocery

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
	 //define
     char choice,a,b,c,exit;
     float numa,numb,numc,suma=0,sumb=0,sumc=0,totalsum;
     float moneya,moneyb,moneyc,money,charge,totalcost,grandtotal; 
     //shopping
     do{
     	  printf("Please input your choice:\n");
		  printf("a for artichokes,b for beets ,c for carrots\n");
     	  scanf("\n%c",&choice);
     switch (choice){
     	case 'a':
     		printf("please input how many pounds you want for artichokes:\n");
     		scanf("%f",&numa);
     		suma=suma+numa;
     		printf("you have bought %5.2f pounds artichokes\n",suma);
     	case 'b':
     		printf("please input how many pounds you want for beets:\n");
     		scanf("%f",&numb);
     		sumb=sumb+numb;	
     		printf("you have bought %5.2f pounds beets\n",sumb);
     	case 'c':
     		printf("please input how many pounds you want for carrots:\n");
     		scanf("%f",&numc);
     		sumc=sumc+numc;	
     		printf("you have bought %5.2f pounds carrots\n",sumc);
         	printf("If you want to exit shopping please input q\n");
     	    scanf("\n%c",&exit);
     }
}while(exit!='q');
       moneya=suma*2.05;
       moneyb=sumb*1.15;
       moneyc=sumc*1.09;
        totalsum=suma+sumb+sumc;
        //dicount
        money=suma*2.05+sumb*1.15+sumc*1.09;
        //the cost per pound
        printf("artichokes $2.05per pound,beets $1.15per pound,carrots $1.09 per pound\n");
        //the pounds ordered 
        printf("you ordered %5.2f pounds artichokes\n",suma);
        printf("you ordered %5.2f pounds beets\n",sumb);
        printf("you ordered %5.2f pounds carrots\n",sumc);
        if(money<100&&totalsum<=5){
        	totalcost=moneya+moneyb+moneyc;
        	charge=6.50;
        	grandtotal=totalcost+charge;
        printf("the cost for artichokes=$%5.2f\n",moneya);
        printf("the cost for beets=$%5.2f\n",moneyb);
        printf("the cost for carrots=$%5.2f\n",moneyc);
        }
        else if(money<100&&totalsum>5&&totalsum<20){
        	totalcost=moneya+moneyb+moneyc;
        	charge=14.00;
        	grandtotal=totalcost+charge;
        	printf("the cost for artichokes=$%5.2f\n",moneya);
            printf("the cost for beets=$%5.2f\n",moneyb);
            printf("the cost for carrots=$%5.2f\n",moneyc);
        }
		else if(money<100&&totalsum>=20){
			totalcost=moneya+moneyb+moneyc;
        	charge=14.00+0.5*totalsum;
        	grandtotal=totalcost+charge;
        	printf("the cost for artichokes=$%5.2f\n",moneya*0.95);
            printf("the cost for beets=$%5.2f\n",moneyb*0.95);
            printf("the cost for carrots=$%5.2f\n",moneyc*0.95);
		}
		
		if(money>=100&&totalsum<=5){
			totalcost=(moneya+moneyb+moneyc)*0.95;
        	charge=6.50;
        	grandtotal=totalcost+charge;
        	printf("the dicount is 0.95\n");
        	printf("the cost for artichokes=$%5.2f\n",moneya*0.95);
            printf("the cost for beets=$%5.2f\n",moneyb*0.95);
            printf("the cost for carrots=$%5.2f\n",moneyc*0.95);
		}
        else if(money>=100&&totalsum>5&&totalsum<20){
        	totalcost=(moneya+moneyb+moneyc)*0.95;
        	charge=14.00;
        	grandtotal=totalcost+charge;
        	printf("the dicount is 0.95\n");
        	printf("the cost for artichokes=$%5.2f\n",moneya*0.95);
            printf("the cost for beets=$%5.2f\n",moneyb*0.95);
            printf("the cost for carrots=$%5.2f\n",moneyc*0.95);
        }
		else if(money>=100&&totalsum>=20){
			totalcost=(moneya+moneyb+moneyc)*0.95;
        	charge=14.00+0.5*totalsum;
        	grandtotal=totalcost+charge;
        	printf("the dicount is 0.95\n");
        	printf("the cost for artichokes=$%5.2f\n",moneya*0.95);
            printf("the cost for beets=$%5.2f\n",moneyb*0.95);
            printf("the cost for carrots=$%5.2f\n",moneyc*0.95);
			
		}
		printf("the total cost of the order is $%5.2f\n",totalcost);
		printf("the shipping charge is $%5.2f\n",charge);
		printf("the grand total of all the charges is $%5.2f\n",grandtotal);
		 
    	system("pause");
    	return 0;
}
	
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zero B612

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值