Advertisement
Lisaveta777

Prata chapter 7 exs 10

Aug 9th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. //is 50 string ok to use?
  2. //in switch(): is it ok to put break into the same string, as operator, when operator is short?
  3. //
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. #define RATE1 0.15
  7. #define RATE2 0.28
  8. #define CUTOFF1 17850.0
  9. #define CUTOFF2 23900.0
  10. #define CUTOFF3 29750.0
  11. #define CUTOFF4 24750.0
  12.  
  13. float calc(int,float);
  14.  
  15. int main()
  16. {
  17.     int type;
  18.     float salary;
  19.     while(1)
  20.     {
  21.         printf("what is your tax type?(0 for exit)\n");
  22.         printf("1.single 2. head 3. married 4. separated\n");
  23.         scanf("%d",&type);
  24.         if(type==0)
  25.             break;
  26.  
  27.         printf("Enter your salary, please\n");
  28.         scanf("%f",&salary);
  29.         calc(type,salary);
  30.  
  31.     }
  32.  
  33.     return 0;
  34. }
  35. float calc(int typ, float s)
  36. {
  37.     float tax,cut_off;
  38.     switch(typ)
  39.     {
  40.     case 1:
  41.         cut_off = CUTOFF1;   break;
  42.     case 2:
  43.         cut_off = CUTOFF2;   break;
  44.     case 3:
  45.         cut_off = CUTOFF3;   break;
  46.     case 4:
  47.         cut_off = CUTOFF4;   break;
  48.     default:                 break;
  49.     }
  50.     tax = s<cut_off? s*RATE1: cut_off*RATE1 +(s-cut_off)*RATE2; //tax calculation
  51.     printf("tax is  %f\n\n",tax);
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement