Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //prata exc 7 chapter 7
- //working, but i'm not happy about names vars and consts
- //have to read a book about properly naming!
- //another matter - which is better style -introducing after_tax or not?
- #include <stdio.h>
- #include <ctype.h>
- #define H_RATE 10.0 //hourly rate
- #define O_RATE 15.0 //overtime rate
- #define TAX1 0.15
- #define TAX2 0.2
- #define TAX3 0.25
- #define BREAK1 300.0
- #define BREAK2 450.0
- #define WEEK 40.0
- int main()
- {
- float hours,before_tax, after_tax, tax;
- printf("How many hours have you worked this week?\n");
- scanf("%f",&hours);
- //calculating salary before tax
- if(hours<=WEEK)
- before_tax = hours * H_RATE;
- else
- before_tax = WEEK*H_RATE +(hours-WEEK)*O_RATE;
- //calculating taxes
- if(before_tax<BREAK1)//if salary less than 300
- {
- tax = before_tax*TAX1;
- }
- else if(before_tax<BREAK2)//if salary less than 450
- {
- tax = BREAK1*TAX1+ (before_tax-BREAK1)*TAX2;
- }
- else //salary equal or over 450
- tax = BREAK1*TAX1 + (BREAK2-BREAK1)*TAX2+ (before_tax-BREAK2)*TAX3;
- after_tax = before_tax - tax;
- printf("before %f, after %f, tax %f",before_tax,after_tax,tax);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement