Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #define BASE1 8.50
- #define BASE2 9.50
- #define BASE3 10.00
- #define BASE4 11.0
- #define WEEK 40.0
- #define OTIME 1.5
- #define TRATE1 0.15
- #define TRATE2 0.20
- #define TRATE3 0.25
- #define TBREAK1 300.0
- #define TBREAK2 450.0
- float salary_count(int);
- float tax_count(float);
- int main(void)
- {
- char ch;
- float sal,tax;
- printf("1)%f 2)%f 3)%f 4)%f Q for exit\n",BASE1,BASE2,BASE3,BASE4);
- while((ch = getchar())!= 'Q')
- {
- sal = 0.0;
- if(ch== '1'|| ch=='2'|| ch=='3' || ch == '4' )
- {
- sal = salary_count(ch);
- printf("salary %f\n",sal);
- }
- else
- printf("your input is wrong, try again\n");
- if(sal)//counting taxes, if sal>0
- {
- tax = tax_count(sal);
- }
- printf("tax is %f\n",tax);
- printf("1)%f 2)%f 3)%f 4)%f Q for exit\n",BASE1,BASE2,BASE3,BASE4);
- while(getchar()!='\n')//gets rid of input, including '\n'
- continue;
- }
- return 0;
- }
- float salary_count(int c)
- {
- float hours,hourly_rate,result;
- printf("How many hours have you done this week?\n");
- scanf("%f",&hours);
- switch(c)
- {
- case '1':
- hourly_rate = BASE1;
- break;
- case '2':
- hourly_rate = BASE2;
- break;
- case '3':
- hourly_rate = BASE3;
- break;
- case '4':
- hourly_rate = BASE4;
- break;
- default:
- printf("nedopustimyi vvod\n");
- }//end of switch
- if(hours<=40)
- result = hours*hourly_rate;
- else
- result = (hours-WEEK)*hourly_rate*OTIME +WEEK*hourly_rate;
- return result;
- }
- float tax_count(float s)
- {
- float t;
- if(s<=TBREAK1)
- t = s*TRATE1;
- else if(s<=TBREAK2)
- t = (s-TBREAK1)* TRATE2+ (TBREAK1)*TRATE1;
- else
- t = (s-TBREAK2)*TRATE3 +(TBREAK2-TBREAK1)*TRATE2+ TBREAK1*TRATE1;
- return t;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement