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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
void welcomeMsg()
{
cout << "Welcome to my program";
cout << endl;
}
double totalPay(string workerName, int numOFHours, int hourlyRate, int stateTax, int fedTax)
{
double grossPay, netPay;
grossPay = (numOFHours * hourlyRate);
netPay = grossPay - ((grossPay * (stateTax / 100)) + (grossPay * (fedTax / 100)));
return netPay;
}
void showResults(string workerName, double numOFHours, double hourlyRate, double stateTax, double fedTax)
{
double grossPay, netPay;
grossPay = (numOFHours * hourlyRate);
stateTax = grossPay * (stateTax / 100);
fedTax = grossPay * (fedTax / 100);
netPay = grossPay - (stateTax + fedTax);
cout << workerName << " works for " << numOFHours << "Hours for " << hourlyRate << "$ /Hour ," << endl;
cout << "State Tax of " << stateTax << " and Federal Taxes of " << fedTax << endl;
cout << "The worker gets: " << grossPay << "$ and netpay of: " << netPay << "$";
}
double grossPay(string workerName, int numOFHours, int hourlyRate, int stateTax, int fedTax)
{
double grossPay;
grossPay = (numOFHours * hourlyRate);
return grossPay;
}
int main()
{
int numOFHours, stateTax, fedTax, N = 1, numOfWorkers;
double hourlyRate, totalGrossPay, averageGrossPay;
string workerName;
char addAnotherOne;
welcomeMsg();
do
{
cout << endl << "please enter the number of workers you want to calculate: ";
cin >> numOfWorkers;
for (int f = 0; f < numOfWorkers; f++)
{
cout << "Please enter worker" << N << " name: ";
cin >> workerName;
N = N++;
do
{
cout << "Please enter the number of hours worked: ";
cin >> numOFHours;
if (numOFHours < 0)
{
cout << "You entered invalid number, please reenter valid number";
}
if (numOFHours > 60)
{
cout << "Maximum number of hours is 60";
}
} while ((numOFHours < 0) || (numOFHours > 60));
do
{
cout << "Please enter hourly pay rate: ";
cin >> hourlyRate;
if (hourlyRate <= 0)
{
cout << "You entered invalid number, please reenter valid number";
}
if (hourlyRate > 42.47)
{
cout << "Maximum hourly rate is 42.47";
}
} while ((hourlyRate <= 0) || (hourlyRate > 42.47));
do
{
cout << "Please enter the percentage of you state tax: ";
cin >> stateTax;
if (stateTax < 0)
{
cout << "You entered invalid number, please reenter valid number";
}
if (stateTax > 10)
{
cout << "Maximum state tax is 10%";
}
} while ((stateTax < 0) || (stateTax > 10));
do
{
cout << "Please enter the percentage of you Federal tax: ";
cin >> fedTax;
if (fedTax < 0)
{
cout << "You entered invalid number, please reenter valid number";
}
if (fedTax > 25)
{
cout << "Maximum Federal tax is 25%";
}
} while ((fedTax < 0) || (fedTax > 25));
showResults(workerName, numOFHours, hourlyRate, stateTax, fedTax);
cout << endl;
totalGrossPay += totalPay(workerName, numOFHours, hourlyRate, stateTax, fedTax);
}
cout << endl;
averageGrossPay = (totalGrossPay / numOfWorkers);
cout << "There are " << numOfWorkers << " workers with total gross pay of " << totalGrossPay << "$ and average gross pay of " << averageGrossPay << "$" << endl << endl;
cout << "Do you need to add another worker? y/n" << endl;
cin >> addAnotherOne;
} while (addAnotherOne != 'n');
system("PAUSE");
return 0;
}
|