본문 바로가기
C and C++/C and C++ Examples

[C Examples] 세금 계산기 예제코드: if, else if

by Henry Cho 2023. 2. 19.
728x90

세금 계산기 예제코드: if, else if

포스트 난이도: HOO_Intern


# Example Codes

 

#include <stdio.h>
#include <stdlib.h>

int main()
{

    float salary,tax;

    tax = 0;

    printf("Income: $");
    scanf("%f",&salary);

    if (salary < 1000)
    {
        tax = 0.01 * salary;
    }

    else if (salary < 2000)
    {
        salary=salary-1000;
        tax = 0.01 * salary;
        tax = tax + 10;
    }

    else if (salary<4000)
    {
        salary=salary-2000;
        tax = 0.02 * salary;
        tax = tax + 40;
    }

    else if (salary<6000)
    {
        salary=salary-4000;
        tax = 0.03 * salary;
        tax = tax + 60;
    }

    else if (salary<10000)
    {
        salary=salary-6000;
        tax = 0.04 * salary;
        tax = tax + 100;
    }

    else
    {
        salary=salary-10000;
        tax = 0.05 * salary;
        tax = tax + 100;
    }

    printf("Amount of tax: $%.2f \n", tax);
    printf("Coded by HOO.\n");
    return 0;
}

Income: $8000
Amount of tax: $180.00 
Coded by HOO.

Income: $12000
Amount of tax: $200.00 
Coded by HOO.

 

728x90

댓글