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 67 68 69 70 71 72 73 74 75 76 77
|
# include <iostream>
# include <iomanip>
# include <cmath>
using namespace std;
//function prototypes
double getGrossPay(double regPay, double ovrTimePay, double hrsWrk, double payRate, double grossPay);
double getTotalGrossPay(double grossPay, int acc, double totalGrossPay);
int main()
{
//declare variables
double hrsWrk = 0.0;
double payRate = 0.0;
double regPay = 0.0;
double grossPay = 0.0;
double totalGrossPay = 0.0;
double ovrTimePay = 0.0;
int acc = 0;
char sentinel = ' ';
//priming the loop
cout << "Do you have hours to enter? Y/N(N to stop):";
cin >> sentinel;
while (toupper(sentinel) == 'Y')
{
cout << "Enter hours worked:" << endl;
cin >> hrsWrk;
cout << "Enter pay rate:" << endl;
cin >> payRate;
//call function for indiv. grossPay
grossPay = getGrossPay(regPay, ovrTimePay, hrsWrk, payRate, grossPay);
//Display information
cout << fixed << setprecision(2);
cout << "grossPay:$" << grossPay << endl;
cout << "Do you have any more hours to enter? (Y/N):" << endl;
cin >> sentinel;
} //end while
//call function for total gross pay
totalGrossPay = getTotalGrossPay(grossPay, acc, totalGrossPay);
cout << "totalGrossPay:$" << totalGrossPay << endl;
system("pause");
return 0;
}
//function definitions
double getGrossPay(double regPay, double ovrTimePay, double hrsWrk, double payRate, double grossPay)
{
//calculates and returns the gross Pay
if (hrsWrk <= 40)
{
regPay = hrsWrk * payRate;
grossPay = regPay + ovrTimePay;
}
else
{
(hrsWrk > 40);
ovrTimePay = (hrsWrk - 40) * (payRate * 1.5) + (40 * payRate);
grossPay = ovrTimePay + regPay;
}// end if
return grossPay;
}//end of function
// calculates the total gross pay //issue is somewhere in here
double getTotalGrossPay(double grossPay, int acc, double totalGrossPay)
{
acc += grossPay;
totalGrossPay = acc + grossPay;
return totalGrossPay;
} //end of function
|