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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <iomanip> setprecision
using namespace std;
//global variables
double hours; //hours worked
double rate; //rate of pay
double regPay; //regular hours worked pay
double otPay; //overtime pay
double totalGrossPay;
int week;
int i = 0;
//function prototypes
void calculateWeek(int, int); //calculates the weeks needed
double calculateRegPay(double, double); //calculates regular pay
double calculateOtPay(double, double, double); //calculates overtime pay
double calculateTotalPay(double, double, double); //calculates the total gross pay for the month
//main function
int main()
{
calculateWeek(i, week);
//if statement
if (hours <= 40)
{
double regPay = calculateRegPay(hours, rate); //calling the function for calculating the regular hours pay
//cout << "The gross pay for this week is $" << regPay;
}
else if (hours > 40)
{
double otPay = calculateOtPay(hours, rate, otPay); //calling the function for calculating the overtime pay
return 0;
}
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%% The gross pay for this week is $" << setprecision(2) << fixed << otPay << " %%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
//end the if statement
//call a function
double totalGrossPay = calculateTotalPay (regPay, otPay, totalGrossPay); //calls function to calculate the total pay for the month
return 0;
}
//end main function
//function week calculation definition
void calculateWeek(int i, int week)
{
for (i = 0; i<4; ++i) {
cout << "Enter info for week " << (i + 1) << endl;
cout << "***************************" << endl;
cout << endl;
cout << "Enter hours worked or 0 to : ";
cin >> hours;
cout << endl;
while (hours != 0)
{
cout << "Enter hourly rate for the employee using this format (00.00): ";
cin >> rate;
cout << "\nEnter hours worked or 0 to exit: ";
cin >> hours;
cout << endl;
}}
}
//function regular pay definition
double calculateRegPay (double hours, double rate)
{
regPay = hours * rate;
return regPay;
}
//end function
//function overtime pay definition
double calculateOtPay(double hours, double rate, double otPay)
{
otPay = (hours > 40);
otPay = (hours - 40) * (rate * 1.5) + (rate * 40);
return otPay;
}
//end function
//function total gross pay definition
double calculateTotalPay(double regPay, double otPay, double totalGrossPay)
{
totalGrossPay += (regPay + otPay);
return totalGrossPay;
}
//end function definition
|