Explanation of the program
This program calculates the salary of an employee using switch case. The basic pay is read into the variable bp. If bp greater than Rs. 10000 then ta is 5 % of bp, da is 3% of bp and tax is 2% of bp, if bp greater than Rs. 20000 then ta is 7 % of bp, da is 5% of bp and tax is 3% of bp, if bp greater than Rs. 30000 then ta is 9 % of bp, da is 7% of bp and tax is 4% of bp, otherwise ta is 9 % of bp, da is 7% of bp and tax is 4% of bp. Here bp is divided by 10000 and the result is stored in bp1, it is then given as input to the switch case, to find the appropriate values of ta, da and tax.
After exiting from the switch case, the total salary is calculated by using the equation bp+(ta+da)-tax and it is stored in the variable tot.
code:-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int bp1;
float bp,ta,da,tax,tot;
printf("Enter the basic pay");
scanf("%f",&bp);
bp1=bp/10000;
switch(bp1)
{
case 1:ta=bp*5/100;
da=bp*3/100;
tax=bp*2/100;
break;
case 2:ta=bp*7/100;
da=bp*5/100;
tax=bp*3/100;
break;
case 3:ta=bp*9/100;
da=bp*7/100;
tax=bp*4/100;
break;
default:ta=bp*10/100;
da=bp*9/100;
tax=bp*5/100;
break;
}
tot=bp+(ta+da)-tax;
printf("ta=%f \nda=%f \ntax=%f",ta,da,tax);
printf("\n\nTotal is %f",tot);
getch();
}
#include<conio.h>
void main()
{
clrscr();
int bp1;
float bp,ta,da,tax,tot;
printf("Enter the basic pay");
scanf("%f",&bp);
bp1=bp/10000;
switch(bp1)
{
case 1:ta=bp*5/100;
da=bp*3/100;
tax=bp*2/100;
break;
case 2:ta=bp*7/100;
da=bp*5/100;
tax=bp*3/100;
break;
case 3:ta=bp*9/100;
da=bp*7/100;
tax=bp*4/100;
break;
default:ta=bp*10/100;
da=bp*9/100;
tax=bp*5/100;
break;
}
tot=bp+(ta+da)-tax;
printf("ta=%f \nda=%f \ntax=%f",ta,da,tax);
printf("\n\nTotal is %f",tot);
getch();
}
Post a Comment
If you have any doubts, Please let me know
Thanks!