朝鲜蓟 甜菜 胡萝卜 按规则计算价格以及运费(图)


#include "stdAfx.h"
#include "ctype.h" //需要调用tolower函数
#include "stdlib.h"
#define CXJ 1.25 //朝鲜蓟的售价
#define TC 0.65 //甜菜的售价
#define HLB 0.89 //胡萝卜的售价
#define ONEHUI 0.05 //100美元的优惠
#define DOWNHUI 3.50 //五磅以下的订单收取的装卸费
#define MEDHUI 10.00 //超过五磅不足二十磅收取的装卸费
#define BIGHUI 0.1//20磅或以上的运输在8美元的基础上每磅加收0.1美元

int main(void)
{
	char ch;
	double sum=0.0,ave=0.0,cxj=0.0,tc=0.0,hlb=0.0;

	printf("Please input a to c for Purchase:\n");
	printf("a is artichoke Selling price 1.25$\tb is Beet Selling price 0.65$\nc is Carrot Selling price 0.89$\t\tq to quit\n:");
	while((ch=tolower(getchar()))!='q')
	{
		switch(ch)	
		{
			case 'a':printf("You want to buy a number of Artichoke : ");
				scanf("%lf",&cxj);
				printf("Enter the Q exit Input a, b, c continues to : ");continue;
			case 'b':printf("You want to buy a number of Beet : ");
				scanf("%lf",&tc);
				printf("Enter the Q exit Input a, b, c continues to : ");continue;
			case 'c':printf("You want to buy a number of Carrot : ");
				scanf("%lf",&hlb);
				printf("Enter the Q exit Input a, b, c continues to : ");continue;
			default :break; 
		}

	}

		ave=(cxj*CXJ+tc*TC+hlb*HLB);
		sum=(cxj+tc+hlb);

		if(sum<5)
			ave+=DOWNHUI;
		else if(sum>5&&sum<20)
			ave+=MEDHUI;
		else if(sum>=20&&sum<100)
			ave=sum*0.1+8;

		if(ave>=100)
			printf("Your cost is : %0.2lf\n",ave-ave*ONEHUI);
		else
			printf("Your cost is : %0.2lf\n",ave);

	system("pause");

	return 0;
}


你可能感兴趣的:(c,System,input,include)