Given the basic salary of an employee, calculate its gross salary according to the following conditions:
Basic Salary Range | HRA (House Rent Allowance) | DA (Dearness Allowance) |
---|---|---|
Basic Salary ≤ 10000 | 20% of basic | 80% of basic |
Basic Salary ≤ 20000 | 25% of basic | 90% of basic |
Basic Salary > 20000 | 30% of basic | 95% of basic |
Formula: Gross Salary = Basic Salary + HRA + DA
Enter an integer indicating the basic salary as input
Print the output as floating point value (2 decimal places) indicating the gross salary Format: Rs.XXXXX.XX
-10^9 <= INPUT <= 10^9
#include <iostream> #include <iomanip> using namespace std; int main() { long long basic; long double gross; cin >> basic; if (basic <= 10000) gross = basic + basic * 0.2 + basic * 0.8; else if (basic <= 20000 && basic > 10000) gross = basic + basic * 0.25 + basic * 0.9; else if (basic > 20000) gross = basic + basic * 0.3 + basic * 0.95; cout << fixed << setprecision(2) << "Rs." << gross; return 0; }
fixed
and setprecision(2)
for 2 decimal placesint
for calculations involving percentages - precision will be lost&& basic > 10000
in second condition is actually redundant due to else-if logic