C Primer Plus Chapter 7 Question 7

C Primer Plus Chapter 7 Question 7

#include<stdio.h>
#define RATE1 0.15
#define RATE2 0.20
#define RATE3 0.25
#define BASE1 300
#define BASE2 400
#define BASE3 450
#define TAX1 BASE1 * RATE1
#define TAX2 TAX1 + (BASE2 - BASE1) * RATE2
#define TAX3 75


int main()
{
    
     
 int x;     // 工作时间 
 const int boundry_hours = 40;
 int allincome = 0;
 float realincome = 0.0;
 float tax = 0.0;
 
 printf("Please enter your work hours:\n");
 scanf("%d", &x);
 if(x < boundry_hours)
 {
    
    
  allincome = x * 10;
  if(allincome <= BASE1)
   tax = allincome * RATE1;
  if((allincome > BASE1) && (allincome <= BASE2))
   tax = TAX1 + (allincome - BASE1) * RATE2;
  realincome = allincome - tax;
  printf("总工资为:%d, 税金为: %f, 最终的工资为:%f", allincome, tax, realincome);
 }
 
 if(x == boundry_hours)
  {
    
    
  allincome = 40 * 10;
  tax = TAX2;
  realincome = allincome - tax;
  printf("总工资为:%d, 税金为: %f, 最终的工资为:%f", allincome, tax, realincome);
  }

if(x > boundry_hours)
 {
    
    
  allincome = BASE2 + (x - boundry_hours) * 15;
  if((allincome > BASE2) && (allincome < BASE3))
   tax = TAX2 + ( x - boundry_hours) * RATE3;
if(allincome == BASE3)
   tax = TAX3;
  if(allincome > BASE3)
   tax = TAX3 + (allincome - BASE3) * RATE3;
   realincome = allincome - tax;
   printf("总工资为:%d, 税金为: %f, 最终的工资为:%f", allincome, tax, realincome); 
 }
 return 0;
 }

Guess you like

Origin blog.csdn.net/xdg15294969271/article/details/108024129