Using the switch .... case statement. Write a program in C
Write a program in C to enter employee name his categories and basic pay then calculate and print his net salary with the formula
net salary (ns) = basic pay (bp) + hra - pf.
where hra and pf are calculated as per the following rules.
For eg :-
Output :-
Enter employee name, category and basic pay
Fransis 0 10000
Net salary = Rs. 10600.000000
net salary (ns) = basic pay (bp) + hra - pf.
where hra and pf are calculated as per the following rules.
Category | hra | pf |
o - officer | 15% of bp | 9% of bp |
m - manager | 10% of bp | 8% of bp |
w - worker | 5% of bp | 7% of bp |
#include< #include< #include< void main() { char cat, name [20]; float bp, hra, pf, ns; clrscr(); printf("Enter employee name, category and basic pay \n"); scanf("%s %c %f", name, &cat, &bp); switch(cat) { case 'o' : hra = bp * 0.15; pf = bp * 0.09; break; case 'm' : hra = bp * 0.1; pf = bp * 0.08; break; case 'w' : hra = bp * 0.05; pf = bp * 0.07; break; default : hra = 0.0; pf = 0.0; } ns = bp + hra - pf; printf("Net salary = Rs. %f \n", ns); } |
---|
For eg :-
Output :-
Enter employee name, category and basic pay
Fransis 0 10000
Net salary = Rs. 10600.000000
0 comments:
Post a Comment