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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
//Function Prototypes
void displayInstructions();
float getRate();
float getHours();
float calculateMath(float payRate, float totalhour);
void displayResults(string name, float grosspay, float totalWithholdings, float netPay);
//Main Function
int main()
{
displayInstructions();
return 0;
}
//Function Definitions
//Function 1
void displayInstructions()
{
string name;
float payRate;
float totalhour, grosspay, totalWithholdings, netPay;
cout << "Enter the name of the employee: ";
cin >> name;
if (name != "done")
{
getRate();
getHours();
calculateMath(payRate, totalhour);
displayResults(name, grosspay, totalWithholdings, netPay);
}
else
{
cout << "Bye!" << endl;
}
}
//Tax Rate
float getRate()
{
float payRate;
cout << "Enter the hourly pay rate: ";
cin >> payRate;
return payRate;
}
//Hours Worked
float getHours()
{
int x = 1;
float hour;
float totalhour = 0;
while (x <= 5)
{
cout << "Enter the number of hours worked for Day " << x << ": ";
cin >> hour;
totalhour = totalhour + hour;
x = x + 1;
}
return totalhour;
}
//Calculate Gross Pay, Withholdings, and Net Pay
float calculateMath(float payRate, float totalhour)
{
float grosspay;
float withholdingsTax, totalWithholdings, netPay;
int state = .0125;
int fica = .0765;
int federal;
grosspay = payRate * totalhours;
if (grosspay < 500)
{
federal = .15;
}
else
{
federal = .25;
}
withholdingsTax = state + fica + federal;
totalWithholdings = grosspay / withholdingsTax;
netPay = grosspay - totalWithholdings;
return grosspay, totalWithholdings, netPay;
}
//Displaying Results
void displayResults(string name, float grosspay, float totalWithholdings, float netPay)
{
cout << setprecision(2) << fixed;
cout << left;
cout << endl;
cout << "Payroll" << endl;
cout << "======================================" << endl;
cout << endl;
cout << setw(25) << "Employee Name:" << name << endl;
cout << setw(25) << "Gross Pay:" << "$" << grosspay << endl;
cout << setw(25) << "Total Withholding:" << "$" << totalWithholdings << endl;
cout << setw(25) << "Net Pay:" << "$" << netPay << endl;
}
|