U.S. federal government employees are paid on a scale according to their grade a
ID: 3850518 • Letter: U
Question
U.S. federal government employees are paid on a scale according to their grade and step. There are a total of 15 grades, each of which consists of 10 steps. Here's a table of 2017 annual salaries (in exist) for the first 3 grades and the first 4 steps from each: Write a program that uses the switch statement to determine the salary of an employee. Your program should allow the user enter two inputs: the grade and step. It should then display the appropriate salary based on the table above. You need to implement only the first 3 grades and first 4 steps. Include default cases to cover situations where the user enters an invalid grade or step. Do not use any form of the if statement in your program.Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int grade,step,salary;
salary = 0;
cout<<" Enter the values of Grade and step : ";
cin>>grade>>step;
switch(grade)
{
case 1:
switch(step) //nested switch
{
case 1: salary = 18526;
break;
case 2: salary = 19146;
break;
case 3: salary = 19762;
break;
case 4: salary = 20375;
break;
default: cout<<" Invalid step value ";
break;
}
break;
case 2: switch(step)
{
case 1: salary = 20829;
break;
case 2: salary = 21325;
break;
case 3: salary = 22015;
break;
case 4: salary = 22599;
break;
default: cout<<" Invalid step value ";
break;
}
break;
case 3: switch(step)
{
case 1: salary = 22727;
break;
case 2: salary = 23485;
break;
case 3: salary = 24243;
break;
case 4: salary = 25001;
break;
default: cout<<" Invalid step value ";
break;
}
break;
default: cout<<" Invalid Grade value ";
break;
}
cout<<" Salary of the employee = $"<<salary;
return 0;
}
Output:
Enter the values of Grade and step : 1 4
Salary of the employee = $20375
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.