here is the question and the code whats wrong i keep getting errors The payroll
ID: 3606885 • Letter: H
Question
here is the question and the code whats wrong i keep getting errors
The payroll manager at Gerston Blankets wants a program that calculates and displays the gross pay for
each of the company’s employees. It also should calculate and display the total gross pay. The payroll
manager will enter the number of hours the employee worked and his or her pay rate. Employees
working more than 40 hours should receive time and one-half for the hours over 40. Use a value-
returning function to determine an employee’s gross pay. Use a different value-returning function to
accumulate the total gross pay. The program should display the total gross pay only after the payroll
manager has finished entering the data for all the employees. Use a sentinel value to end the program.
C++ code:
#include <iostream>
#include <iomanip>
using namespace std;
// prototypes
double getGrossPay(int hours, double payRate, double &grossPay);
double calcTotalGross(double grossPay, double totalGross);
int main()
{
// delare
int hours = 0;
double payRate = 0;
double grossPay = 0;
double totalGrossPay = 0;
cout << "Hours worked: ";
cin >> hours;
if (hours != -1)
{
cout << "Pay rate:";
cin >> hours;
}
while (hours != -1)
{
getGrossPay(hours, payRate, grossPay);
totalGrossPay = calcTotalGross(grossPay, totalGrossPay);
cout << "Hours worked";
cin >> hours;
if (hours != -1)
{
cout << "Payrate";
cin >> payRate;
}
}//endwhile
//display the total gross pay
cout << fixed << setprecision(2);
cout << "Total gross pay is $" << totalGrossPay <<
endl;
system("pause");
return 0;
// function def
double getGrossPay(int hours, double payRate, double &grossPay);
{
//declare variables
int overtimeHours = 0;
if (hours > 40)
{
overtimeHours = hours - 40;
grossPay = (40 * payRate) + (overtimeHours * 1.5 * payRate);
}
else
grossPay = hours * payRate;
//endif
} //end of getGrossPay
double calcTotalGross(double grossPay, double totalGrossPay);
{
//declare variables
double totalGross = 0.0;
totalGross = totalGrossPay + grossPay;
}
}
Explanation / Answer
Hi
I have fixed all issues and it is working fine now.
#include <iostream>
#include <iomanip>
using namespace std;
// prototypes
void getGrossPay(int hours, double payRate, double &grossPay);
double calcTotalGross(double grossPay, double totalGross);
int main()
{
// delare
int hours = 0;
double payRate = 0;
double grossPay = 0;
double totalGrossPay = 0;
cout << "Hours worked: ";
cin >> hours;
if (hours != -1)
{
cout << "Pay rate:";
cin >> payRate;
}
while (hours != -1)
{
getGrossPay(hours, payRate, grossPay);
totalGrossPay = calcTotalGross(grossPay, totalGrossPay);
cout << "Hours worked";
cin >> hours;
if (hours != -1)
{
cout << "Payrate";
cin >> payRate;
}
}//endwhile
//display the total gross pay
cout << fixed << setprecision(2);
cout << "Total gross pay is $" << totalGrossPay <<
endl;
//system("pause");
return 0;
}
// function def
void getGrossPay(int hours, double payRate, double &grossPay)
{
//declare variables
int overtimeHours = 0;
if (hours > 40)
{
overtimeHours = hours - 40;
grossPay = (40 * payRate) + (overtimeHours * 1.5 * payRate);
}
else
grossPay = hours * payRate;
//endif
} //end of getGrossPay
double calcTotalGross(double grossPay, double totalGrossPay)
{
//declare variables
double totalGross = 0.0;
totalGross = totalGrossPay + grossPay;
return totalGross;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.