# Calculate Salary

In this project, you will create a program that will calculate a company’s cost of operation. Since you will be dealing with money, you will need to use a double datatype when creating your variables that hold currency amounts. The program will prompt the user for the number of employees that you will be processing. It should then prompt you to enter in, one employee at a time, the employee’s salary and if they have full benefits or partial benefits.  Here are some of the main variables you will need to create for the program:

• numEmployees                       Holds the number of employees to process
• empSalary                               Holds the salary for a single employee
• fBenefits                                  Indicates if the employee is receiving full benefits
• totalOperatingCost                 Holds the total cost of operation

The above variables should be declared in the main function. Note: there should be no global variables in this program.

When you loop through each employee you should prompt the user for the employees salary and if they are receiving full benefits or only receiving partial benefits. Once you have these two items, at the bottom of the loop, you will call a function to calculate the cost of operation for that specific employee.

The CalcOperating function will have these features:

• No return value
• You will pass 3 arguments
• Salary of the employee
• If the employee is receiving full benefits
• A reference parameter for the operating cost
• Formula for calculating the cost of operation
If the employee receives full benefits
total operating cost += Salary * 1.5
otherwise
total operating cost += Salary * 1.25

You should output the total operating cost to the company of all employees.

Formatting the output: You will need to format the total operating cost with a \$ and 2 decimal points precision.

Program Output:

Cost of Operation

Please enter the number of employees to process: 2

Please enter the salary for employee 1: \$1580.00

Is employee 1 receiving (F)ull or (P)artial benefits? Please enter F or P: F

Please enter the salary for employee 2: \$2368.52

Is employee 2 receiving (F)ull or (P)artial benefits? Please enter F or P: P

Your total operating cost is: \$5330.65

Press any key to continue . . .

Solution

opcost.cpp

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

voidCalcOperating(double empSalary, boolfBenefits, double &totalOperatingCost);

int main() {

intnumEmployees;

doubleempSalary; // salary for a single employee

boolfBenefits;   // indicates if the employee is receiving full benefits

doubletotalOperatingCost; // total cost

string choice;

cout<< ”                Cost of Operation\n\n”;

cout<< “Please enter the number of employees to process: “;

cin>>numEmployees;

if (numEmployees< 0) { // make sure the input is valid

cout<< “error: the number of employees must be positive.” <<endl;

return -1;

}

totalOperatingCost = 0;

for (int i = 0; i <numEmployees; i++) {

cout<< “\nPlease enter the salary for employee ” << (i + 1) << “: \$”;

cin>>empSalary;

if (empSalary< 0) {

cout<< “error: the salary must be positive.” <<endl;

return -1;

}

// ask the user to check if it’s full or partial benefits

cout<< “Is employee ” << (i + 1) << ” receiving (F)ull or (P)artial benefits? “;

cout<< “Please enter F or P: “;

cin>> choice;

fBenefits = (choice == “F”);

// calculate operating cost

CalcOperating(empSalary, fBenefits, totalOperatingCost);

}

cin.ignore(1024, ‘\n’); // consume the new line

// display the result

cout<< “\n\nYour total operating cost is: \$”

<<setprecision(2) << fixed <<totalOperatingCost

<<endl;

cout<< “Press Enter to continue …\n”;

cin.ignore(1024, ‘\n’); // wait until \n is entered

}

voidCalcOperating(double empSalary, boolfBenefits, double &totalOperatingCost) {

// calculate and accumulate the total operating cost

if (fBenefits) {

totalOperatingCost += empSalary * 1.5;

} else  {

totalOperatingCost += empSalary * 1.25;

}

}