Write a program to calculate the total salary of a person. The user has to enter the basic salary (an integer) and the grade (an uppercase character), and depending upon which the total salary is calculated as -
totalSalary = basic + hra + da + allow – pf
where :
hra = 20% of basic
da = 50% of basic
allow = 1700 if grade = ‘A’
allow = 1500 if grade = ‘B’
allow = 1300 if grade = ‘C' or any other character
pf = 11% of basic.
Answers
Answer:
The below code is written in c where we are taking inputs from the users as basic and the grade and with respect to them we are calculating the total salary
#include<stdio.h>
int main()
{ double basic, hra, da, allow, totalsalary;
char grade;
printf("Enter the basic");
scanf("%d" , & basic);
printf("Enter the grade");
scanf("%s" , &grade);
if (grade == 'A')
{ allow = 1700;
}
else if (grade == 'B')
{ allow = 1500;
}
else {
allow = 1300;
}
hra = basic x 0.20
da = basic x 0.50
pf = basic x 0.11
totalsalary = hra + da+ pf+basic+allow
prinft("the total salary will be %d" , totalsalary)
}
}
}
Answer
C++ code
Explanation:
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int basic;
char grade;
cin>>basic;
cin>>grade;
double hra= 0.2*basic;
double da= 0.5*basic;
double pf= 0.11*basic;
int allow;
if(grade=='A'){
allow=1700;
}
else if(grade=='B'){
allow=1500;
}
else{
allow=1300;
}
int totalsalary;
totalsalary= round ( basic + hra + da + allow - pf);
cout<<totalsalary<<endl;
}
// cmath is used for using round function