Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //is 50 string ok to use?
- //in switch(): is it ok to put break into the same string, as operator, when operator is short?
- //
- #include <stdio.h>
- #include <ctype.h>
- #define RATE1 0.15
- #define RATE2 0.28
- #define CUTOFF1 17850.0
- #define CUTOFF2 23900.0
- #define CUTOFF3 29750.0
- #define CUTOFF4 24750.0
- float calc(int,float);
- int main()
- {
- int type;
- float salary;
- while(1)
- {
- printf("what is your tax type?(0 for exit)\n");
- printf("1.single 2. head 3. married 4. separated\n");
- scanf("%d",&type);
- if(type==0)
- break;
- printf("Enter your salary, please\n");
- scanf("%f",&salary);
- calc(type,salary);
- }
- return 0;
- }
- float calc(int typ, float s)
- {
- float tax,cut_off;
- switch(typ)
- {
- case 1:
- cut_off = CUTOFF1; break;
- case 2:
- cut_off = CUTOFF2; break;
- case 3:
- cut_off = CUTOFF3; break;
- case 4:
- cut_off = CUTOFF4; break;
- default: break;
- }
- tax = s<cut_off? s*RATE1: cut_off*RATE1 +(s-cut_off)*RATE2; //tax calculation
- printf("tax is %f\n\n",tax);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement