Advertisement
Lisaveta777

Prata exs 8.7

Aug 22nd, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #define BASE1 8.50
  4. #define BASE2 9.50
  5. #define BASE3 10.00
  6. #define BASE4 11.0
  7. #define WEEK  40.0
  8. #define OTIME 1.5
  9.  
  10. #define TRATE1 0.15
  11. #define TRATE2 0.20
  12. #define TRATE3 0.25
  13. #define TBREAK1 300.0
  14. #define TBREAK2 450.0
  15. float salary_count(int);
  16. float    tax_count(float);
  17. int main(void)
  18. {
  19.     char ch;
  20.     float sal,tax;
  21.     printf("1)%f 2)%f 3)%f 4)%f    Q for exit\n",BASE1,BASE2,BASE3,BASE4);
  22.     while((ch = getchar())!= 'Q')
  23.     {
  24.       sal = 0.0;
  25.        if(ch== '1'|| ch=='2'|| ch=='3' || ch == '4' )
  26.         {
  27.             sal = salary_count(ch);
  28.             printf("salary %f\n",sal);
  29.  
  30.         }
  31.         else
  32.             printf("your input is wrong, try again\n");
  33.  
  34.         if(sal)//counting taxes, if sal>0
  35.         {
  36.             tax = tax_count(sal);
  37.         }
  38.         printf("tax is  %f\n",tax);
  39.         printf("1)%f 2)%f 3)%f 4)%f    Q for exit\n",BASE1,BASE2,BASE3,BASE4);
  40.  
  41.         while(getchar()!='\n')//gets rid of input, including '\n'
  42.             continue;
  43.     }
  44.  
  45.     return 0;
  46. }
  47. float salary_count(int c)
  48. {
  49.     float hours,hourly_rate,result;
  50.     printf("How many hours have you done this week?\n");
  51.     scanf("%f",&hours);
  52.  
  53.     switch(c)
  54.     {
  55.     case '1':
  56.         hourly_rate = BASE1;
  57.         break;
  58.     case '2':
  59.         hourly_rate = BASE2;
  60.         break;
  61.     case '3':
  62.         hourly_rate = BASE3;
  63.         break;
  64.     case '4':
  65.         hourly_rate = BASE4;
  66.         break;
  67.     default:
  68.         printf("nedopustimyi vvod\n");
  69.  
  70.     }//end of switch
  71.  
  72.     if(hours<=40)
  73.         result = hours*hourly_rate;
  74.     else
  75.         result = (hours-WEEK)*hourly_rate*OTIME +WEEK*hourly_rate;
  76.  
  77.     return result;
  78.  
  79. }
  80. float tax_count(float s)
  81. {
  82.     float t;
  83.     if(s<=TBREAK1)
  84.         t = s*TRATE1;
  85.     else if(s<=TBREAK2)
  86.         t = (s-TBREAK1)* TRATE2+ (TBREAK1)*TRATE1;
  87.     else
  88.         t = (s-TBREAK2)*TRATE3 +(TBREAK2-TBREAK1)*TRATE2+ TBREAK1*TRATE1;
  89.     return t;
  90.  
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement