c primer plus 第七章 第十题

c primer plus 第七章 第十题

#include<stdio.h>
#define RATE1 0.15
#define RATE2 0.28
#define BASE1 17850
#define BASE2 23900
#define BASE3 29750
#define BASE4 14875


int main()
{
    
     
 int x;
 float tax;
 char ch;
 printf("Please enter your number firstly:\n");
 scanf("%d", &x);
 printf("Please choose your type secondly: A B C D\n");
 while((ch = getchar()) != '#')
 {
    
    
  switch(ch)
  {
    
    
   case 'A' :
    {
    
    
     if(x < BASE1)
      tax = x * RATE1;
     if(x == BASE1)
      tax = BASE1 * RATE1;
     if(x > BASE1)
      tax = BASE1 * RATE1 + (x - BASE1) * RATE2;
      printf("%f", tax);
     break;
    }
       
   case 'B' :
    {
    
    
     if(x < BASE2)
      tax = x * RATE1;
     if(x == BASE2)
      tax = BASE2 * RATE1;
     if(x > BASE2)
      tax = BASE2 * RATE1 + (x - BASE2) * RATE2;
      printf("%f", tax);
     break;
    }
    
   case 'C' :
    {
    
    
     if(x < BASE3)
      tax = x * RATE1;
     if(x == BASE3)
      tax = BASE3 * RATE1;
     if(x > BASE3)
      tax = BASE3 * RATE1 + (x - BASE3) * RATE2;
      printf("%f", tax);
     break;
    }
    
   case 'D' :
    {
    
    
     if(x < BASE4)
      tax = x * RATE1;
     if(x == BASE4)
      tax = BASE4 * RATE1;
     if(x > BASE4)
      tax = BASE4 * RATE1 + (x - BASE4) * RATE2;
      printf("%f", tax);
     break;
    }
   default :
    break;
   
   
  }
 }
  
 
 return 0;
}

猜你喜欢

转载自blog.csdn.net/xdg15294969271/article/details/108023903
今日推荐