Help solving Rate and Hours Problem

Create a C++ program to calculate and display an employee’s weekly gross pay. The program should ask for the number of work hours in a week and the hourly pay rate, and use these items to calculate gross pay (gross pay = number of work hours * hourly rate). In addition to main(), use the following two functions in your program:

getRateAndHrs(): a void function that asks for hourly rate and number of work hours. Use pass-by-reference to send these two items to main().

calcPay(): a value returning function that calculates and returns gross pay to main().
The main() function should display the gross pay on the computer screen.




#include <iostream>
#include <iomanip>

using namespace std;

void getRateAndHrs(double hours, double rate);

double calcPay(double hours, double rate)
{
double grossPay = 0.0;

grossPay = hours * rate;
return grossPay;
}



int main()
{
double grossPay = 0.0;
double hours = 0.0;
double rate = 0.0;

getRateAndHrs(hours,rate);
//hours = getRateAndHrs();
//rate = getRateAndHrs();
grossPay = calcPay(hours, rate);

cout << "The Employee's Weekly Gross Pay is: $" << grossPay << endl;

system("Pause");
return 0;

}

void getRateAndHrs(double hours, double rate)
{
//double hours;
//double rate;

cout << "Enter the Number of work hours in a week: ";
cin >> hours;
cout << endl;
cout << "Enter Hourly Pay Rate: ";
cin >> rate;
cout << endl;

//return hours, rate;
}
Last edited on
A beginner mistake is thinking that if they post the same thing in multiple places they will get more responses.

I assure you that here, we don't believe in that. Not only do you waist everyone's time reading the same post twice. You confuse the answers you get on multiple threads so that no one is sure what your talking about anymore because it's in a different thread.

Please delete one of these multiple post.
http://www.cplusplus.com/forum/beginner/217731/
if you had read my codes you would have noticed that they were different so could you please help with the code ?
For starters you could wrap your code in code tags to make it more readable.
http://www.cplusplus.com/articles/jEywvCM9/


getRateAndHrs(): a void function that asks for hourly rate and number of work hours. Use pass-by-reference to send these two items to main().
 
void getRateAndHrs(double hours, double rate);
@integralfx

#include <iostream>
#include <iomanip>

using namespace std;

void getRateAndHrs(double hours, double rate);
double calcPay();


int main()
{
double grossPay = 0.0;
double hours = 0.0;
double rate = 0.0;

getRateAndHrs(hours, rate);
grossPay = calcPay();

cout << "The Employee's Weekly Gross Pay is: $" << grossPay << endl;

system("Pause");
return 0;

}

double calcPay()
{
double hours = 0.0;
double rate = 0.0;
double grossPay;

grossPay = hours * rate;
return grossPay;
}

void getRateAndHrs(double hours, double rate)
{
double grossPay;

cout << "Enter the Number of work hours in a week: ";
cin >> hours;
cout << endl;
cout << "Enter Hourly Pay Rate: ";
cin >> rate;
cout << endl;
}


I have used the the void getRateAndHrs (double hours, double rate)... The out come is 0.. could please help
Read the Arguments passed by value and by reference section
http://www.cplusplus.com/doc/tutorial/functions/

Please wrap your code in code tags to make it easier to read.
http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.