#include <stdio.h>
#define ATCH 2.05
#define BT 1.15
#define CRT 1.69
#define SHIP1 6.5
#define SHIP2 14
#define WEIGHT1 5
#define WEIGHT2 20
#define DISCOUNT 0.95
#define LIMIT 100
void check(int at, int bet, int cart);
int main (void)
{
int atch=0, bt=0, crt=0,temp=0;
char label;
printf("Please enter:");
while (scanf_s("%c", &label, sizeof(label)), label != 'q')
{
printf("How many ponds you want?:");
scanf_s("%d", &temp);
switch (label)
{
case 'a':
atch += temp;
break;
case 'b':
bt += temp;
break;
case 'c':
crt += temp;
break;
}
getchar();
printf("Have other vegetables wants to buy enter a~c, q to quit:");
}
check(atch, bt, crt);
return 0;
}
void check(int at, int bet, int cart)
{
float acost = 0, bcost = 0, ccost = 0;
float cost = 0, shipment = 0;
acost = at * ATCH;
bcost = bet * BT;
ccost = cart * CRT;
if (acost + bcost + ccost > LIMIT)
{
cost = (acost + bcost + ccost) * DISCOUNT;
printf("Discount -%.2f\n", (acost + bcost + ccost) * (1 - DISCOUNT));
}
else
cost = acost + bcost + ccost;
if (at + bet + cart <= WEIGHT1)
shipment = SHIP1;
else if (at + bet + cart <= WEIGHT2)
shipment = SHIP2;
else
shipment = SHIP2 + (at + bet + cart - WEIGHT2) * 0.5;
cost += shipment;
printf("artichokes $2.05/p %d %.2f\n", at, acost);
printf("beets $1.15/p %d %.2f\n", bet, bcost);
printf("carrots $1.69/p %d %.2f\n", cart, ccost);
printf("Shipment:%.2f\n", shipment);
printf("All cost:%.2f", cost);
}
c primer plus第七章编程题11
最新推荐文章于 2024-08-07 17:33:57 发布