Advertisement
Lisaveta777

Prata exs 7.7

Aug 9th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. //prata exc 7 chapter 7
  2. //working, but i'm not happy about names vars and consts
  3. //have to read a book about properly naming!
  4. //another matter - which is better style -introducing after_tax or not?
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #define H_RATE 10.0 //hourly rate
  8. #define O_RATE 15.0 //overtime rate
  9. #define TAX1 0.15
  10. #define TAX2 0.2
  11. #define TAX3 0.25
  12. #define BREAK1 300.0
  13. #define BREAK2 450.0
  14. #define WEEK 40.0
  15.  
  16. int main()
  17. {
  18.     float hours,before_tax, after_tax, tax;
  19.     printf("How many hours have you worked this week?\n");
  20.     scanf("%f",&hours);
  21.  
  22.     //calculating salary before tax
  23.     if(hours<=WEEK)
  24.         before_tax = hours * H_RATE;
  25.     else
  26.         before_tax = WEEK*H_RATE +(hours-WEEK)*O_RATE;
  27.  
  28.     //calculating taxes
  29.     if(before_tax<BREAK1)//if salary less than 300
  30.     {
  31.         tax = before_tax*TAX1;
  32.  
  33.     }
  34.     else if(before_tax<BREAK2)//if salary less than 450
  35.     {
  36.         tax = BREAK1*TAX1+ (before_tax-BREAK1)*TAX2;
  37.  
  38.     }
  39.     else //salary equal or over 450
  40.         tax = BREAK1*TAX1 + (BREAK2-BREAK1)*TAX2+ (before_tax-BREAK2)*TAX3;
  41.  
  42.      after_tax = before_tax - tax;
  43.  
  44.      printf("before %f, after %f, tax %f",before_tax,after_tax,tax);
  45.  
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement