Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ console application that asks the user to enter the hourly wage and number of hours worked for each week in a 4-week

Write a C++ console application that asks the user to enter the hourly wage and number of hours worked for each week in a 4-week pay period. Create a custom function with appropriate input parameters and return type that calculates the total gross pay based on the values entered by the user. Use suitable loops for the user input and the processing of data entered by the user. The program should print out the gross pay for the pay period for the employee. The goal of this program is to determine gross pay for a 4-week pay period based on an hourly rate and the number of hours worked in each week of the pay period. Anyone working over 40 hours a given week earns time-and-a-half.

I have tried and looked at several other codings and none of them are computing correctly.

This one gives a strange answer when its ran (4.20244e+007):

#include

using namespace std; double getGrossPay(int numberOfHours, int extraHoours, double hourRate ); int main() { double hourRate; int numberOfWeeks = 4; int numberOfHours; int extraHoours; int totalHours = 0; double grossPay; cout << "Enter Hourly wage amount:"; cin >> hourRate; for(int i=0; i> numberOfHours; if(numberOfHours > 40) { extraHoours = extraHoours + (numberOfHours - 40); } totalHours = totalHours + numberOfHours; } grossPay = getGrossPay(totalHours, extraHoours, hourRate); cout<<"The Gross Pay is "<

double getGrossPay(int totalHours, int extraHoours, double hourRate ) { double grossPay = 0; grossPay = (totalHours - extraHoours) * hourRate; grossPay = grossPay + (extraHoours * hourRate * 1.5); return grossPay; }

This one does not consider overtime:

#include

using namespace std;

//function to calculate the pay for the given wages and hours double calculate_pay(double w,int h) { //returning the result return w * h; }

int main() { //variables to store the wage, hours, total pay double wages[4]; int hours[4]; double pay[4]; double total=0; //variable for counter int i=0; cout<<" ***** SIMPLE WAGE CALCULATOR ******* "<>wages[i]; cout<<"Enter the number of hours for "<>hours[i]; } //loop to calculate the pay for(i=0;i<4;i++) { pay[i]=calculate_pay(wages[i],hours[i]); cout<<" Pay for the week "<

And this one is the one I tried to write from scratch but has alot of errors:

# include

Using namespace std;

//define variables

Double getGrossPay (double pay, double overtimePay);

double hoursWorked;

double payRate;

double grosspay;

double totalGrossPay;

double pay;

double overtimePay;

int numberOfWeeks = 4

int main ()

{

cout << Enter rate of pay: ;

Cin>> payRate;

for(int i=0; i> hoursWorked;

if (hoursWorked <=40)

{

pay = hoursWorked * payRate;

}

else (hoursWorked > 40);

{

overTimePay = (hoursWorked 40) * (payRate * 1.5) + pay

}

grossPay = getGrossPay (pay, overtimePay);

cout<< Grosspay: $ << grossPay;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions