113k views
0 votes
Summary

In this lab, you complete a prewritten C++ program that calculates an employee’s end-of-year bonus and prints the employee’s name, yearly salary, performance rating, and bonus. In this program, bonuses are calculated based on employees’ annual salary and their performance rating.

Instructions
Variables have been declared for you, and the input statements and output statements have been written. Read them over carefully before you proceed to the next step.
Design the logic, and write the rest of the program using a switch statement.
Execute the program by clicking the Run button at the bottom of the screen entering the following as input:
Employee’s name: Jeanne Hanson
Employee’s salary: 70000.00
Employee’s performance rating: 2
Confirm that your output matches the following:
Employee Name: Jeanne Hanson
Employee Salary: $70000
Employee Rating: 2
Employee Bonus: $10500



This is what I have:



// EmployeeBonus.cpp - This program calculates an employee's yearly bonus.


#include
#include
using namespace std;
int main()
{
// Declare and initialize variables here
string employeeFirstName;
string employeeLastName;
double numPerformanceRate;
double numSalary;
double score;
double bonus;
const double BONUS_1 = .10;
const double BONUS_2 = .20;
const double BONUS_3 = .30;
const double BONUS_4 = .40;

const int RATING_1 = 1;
const int RATING_2 = 2;
const int RATING_3 = 3;
const int RATING_4 = 4;

// This is the work done in the housekeeping() function
cout << "Enter employee's first name: ";
cin >> employeeFirstName;
cout << "Enter employee's last name: ";
cin >> employeeLastName;
cout << "Enter employee's salary: ";
cin >> numSalary;
cout << "Employee’s performance rating: ";
cin >> numPerformanceRate;


// This is the work done in the detailLoop()function
// Write your code here


// This is the work done in the endOfJob() function
// Output.
cout << "Employee Name: " << employeeFirstName << " " << employeeLastName << endl;
cout << " Employee Salary: "<< numSalary << endl;
cout << "Employee Rating: " << numPerformanceRate << endl;
cout << "Employee Bonus: $" << bonus << endl;


return 0;
}


what am I doing wrong?

User Grault
by
7.4k points

1 Answer

1 vote

Answer:

You need to write the code that calculates the bonus based on the employee's performance rating and salary. This calculation should be done inside the switch statement and the bonus variable should be updated with the correct value. You can use the numPerformanceRate and numSalary variables to determine the bonus, and the BONUS_1, BONUS_2, BONUS_3, and BONUS_4 constants to calculate the bonus.

Step-by-step explanation:

switch (numPerformanceRate) {

case RATING_1:

bonus = numSalary * BONUS_1;

break;

case RATING_2:

bonus = numSalary * BONUS_2;

break;

case RATING_3:

bonus = numSalary * BONUS_3;

break;

case RATING_4:

bonus = numSalary * BONUS_4;

break;

default:

cout << "Invalid performance rating. Please enter a number between 1 and 4." << endl;

break;

}

User Dbf
by
6.5k points