C++ Exercise help

My code isn't working and my error list won't display so if someone could help me and tell me what is wrong and help me fix it that would be great!!

Prompt:
In this exercise, you create a program that calculates and displays gross pay amounts. The user will enter the number of hours an employee worked and his or her pay rate. The program should contain four value-returning functions: main, getHoursWorked, getPayRate, and calcGross. The main function should call each of the other three functions and then display the gross pay on the screen. When coding the calcGross function, you do not have to worry about overtime pay. You can assume that everyone works 40 or fewer hours per week. The hours worked and rate of pay may contain a decimal place. Use a sentinel value to end the program.





Code:

#include <iostream>
#include <iomanip>
using namespace std;

double getHoursWorked();
double getPayRate();
double calcGross();

int main()
{
//declare variables
double hoursWorked = 0;
double payRate = 0;
double grossPay = 0;

//enter input
hoursWorked = getHoursWorked();
payRate = getPayRate();


grossPay = calcGross();

//display the total points and grade
cout << "Gross Pay: " << grossPay << endl;

system("pause");
return 0;
} //end of main function

double getHoursWorked()
{
double hoursOfWork;

while (hoursOfWork != 0)
{
cout << "Please enter hours worked (enter 0 to stop): ";
cin >> hoursOfWork;
}
return hoursOfWork;

}//end of getHoursWorked function

double getPayRate()
{
double rateOfPay;

while (rateOfPay != 0)
{
cout << "Please enter pay rate (enter 0 to stop): ";
cin >> rateOfPay;
}
return rateOfPay;

}//end of getPayRate function

double calcGross(double workHours, double thePayRate)
{
double calculatedGross = 0.0;

calculatedGross = workHours * thePayRate;

return calculatedGross;


} //end of calcAverage function
getHoursWorked() needs to initialize hoursOfWork to zero. getPayRate() needs to do the same thing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <iomanip>
using namespace std;

double getHoursWorked();
double getPayRate();
double calcGross();

int main()
{
    //declare variables
    double hoursWorked	= 0;
    double payRate	= 0;
    double grossPay	= 0;

    //enter input
    hoursWorked = getHoursWorked();
    payRate	= getPayRate(); 


    grossPay = calcGross();

    //display the total points and grade
    cout << "Gross Pay: " << grossPay << endl;

    system("pause");
    return 0;
} //end of main function

double getHoursWorked()
{
    double hoursOfWork;	

    while (hoursOfWork != 0)
    {
        cout << "Please enter hours worked (enter 0 to stop): ";
        cin >> hoursOfWork;	
    }
    return hoursOfWork;

}//end of getHoursWorked function

double getPayRate()
{
    double rateOfPay;	

    while (rateOfPay != 0)
    {
        cout << "Please enter pay rate (enter 0 to stop): ";
        cin >> rateOfPay;	
    }
    return rateOfPay;

}//end of getPayRate function

double calcGross(double workHours, double thePayRate)
{
    double calculatedGross = 0.0;

    calculatedGross = workHours * thePayRate;

    return calculatedGross;


} //end of calcAverage function 


You did not pass parameter when you call calcGross at line 21. Moreover, your forward declaration of function calcGross() at line 7 is not the same as your calcGross() function definition at line 56 that's why no compile errors found at main() when calling calcGross with no parameters.
You may need to modify your function prototype up top
When I did this I had some data types in the prototype (like int).
Here is the fixed code, understand that and not just simply copy. oks?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <iomanip>
using namespace std;

double getHoursWorked();
double getPayRate();
double calcGross(double workHours, double thePayRate);

int main()
{
    //declare variables
    double hoursWorked	= 0;
    double payRate	= 0;
    double grossPay	= 0;

    //enter input
    hoursWorked = getHoursWorked();
    payRate	= getPayRate();


    grossPay = calcGross(hoursWorked, payRate);

    //display the total points and grade
    cout << "Gross Pay: " << grossPay << endl;

    system("pause");
    return 0;
} //end of main function

double getHoursWorked()
{
    double hoursOfWork;

    //while (hoursOfWork != 0)
    //{
        cout << "Please enter hours worked: ";
        cin >> hoursOfWork;
    //}
    return hoursOfWork;

}//end of getHoursWorked function

double getPayRate()
{
    double rateOfPay;

    //while (rateOfPay != 0)
    //{
        cout << "Please enter pay rate: ";
        cin >> rateOfPay;
    //}
    return rateOfPay;

}//end of getPayRate function

double calcGross(double workHours, double thePayRate)
{
    double calculatedGross = 0.0;

    calculatedGross = workHours * thePayRate;

    return calculatedGross;


} //end of calcAverage function
Topic archived. No new replies allowed.