C Primer Plus 第七章 第10题

#include<stdio.h>
#define LEVEL1 17850
#define LEVEL2 23900
#define LEVEL3 29750
#define LEVEL4 14875
#define TAX1 0.15
#define TAX2 0.28
int main(void)
{
    int situation;
    int income;
    double tax;
    printf("Enter your situation:\n1  Single\n2  House holder\n3  Married"
        "\n4  Divorced\n");
    while ((scanf_s("%d", &situation)) == 1)
    {
        if (situation < 1 || situation>4)
        {
            printf("Enter a correct number.");
            continue;
        }
        printf("Enter your income:");    
        loop:scanf_s("%d", &income);
            switch (situation)
            {
            case 1:
                if (income <= LEVEL1)
                    tax = income * TAX1;
                else
                    tax = LEVEL1 * TAX1 + (income - LEVEL1) * TAX2;
                break;
            case 2:
                if (income <= LEVEL2)
                    tax = income * TAX1;
                else
                    tax = LEVEL2 * TAX1 + (income - LEVEL2) * TAX2;
                break;
            case 3:
                if (income <= LEVEL3)
                    tax = income * TAX1;
                else
                    tax = LEVEL3 * TAX1 + (income - LEVEL3) * TAX2;
                break;
            case 4:
                if (income <= LEVEL4)
                    tax = income * TAX1;
                else
                    tax = LEVEL4 * TAX1 + (income - LEVEL4) * TAX2;
                break;
            default:
                printf("Enter correct income.");
                goto loop;
            }
            printf("Your tax is $%f.\nEnter next situation(input q to quit).\n", tax);
    }
    printf("Bye");
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值