c primer plus第七章编程题11

#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);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值