//Jonathan Messiha CS1A Practicum #1
//
/* *****************************************************************************
* _____________________________________________________________________________
* This program will ask a user to enter financial information for however many
* employees and then use a loop to accumulate and display all totals over a
* specified week.
*
* Computation is based on the following equations:
* grossTotal += grossPay
* stateTotal += stateTax
* federalTotal += federalTax;
* ficaTotal += ficaWithhold;
* netPay = grossPay - (stateTax + federalTax + ficaWithhold)
* netTotal += netPay
*______________________________________________________________________________
* INPUT
* employeeNum: random form of employee identification. Also serves as sentinel.
* grossPay: gross pay for each employee for this week.
* stateTax: state tax owed by each employee this week.
* federalTax: federal tax owed by each employee this week.
* ficaWithhold: FICA withheld from each employee this week.
*
* OUTPUT
* grossTotal: total gross pay of all employees this week.
* stateTotal: total state tax of all employees this week.
* federalTotal: total federal tax of all employees this week.
* ficaTotal: total FICA withheld from all employees this week.
* netTotal: net total pay for all employees this week.
******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// identify variables and initialize count to 0.
int employeeNum, count = 0;
// identify gross pay variables and initialize total to 0.
double grossPay, grossTotal = 0;
// identify state tax variables and initialize total to 0.
double stateTax, stateTotal = 0;
// identify federal tax variables and initialize total to 0.
double federalTax, federalTotal = 0;
// identify FICA variables and initialize total to 0.
double ficaWithhold, ficaTotal = 0;
// identify net pay variables and initialize total to 0.
double netPay, netTotal = 0;
// Asks for and receives employee number from user.
cout << "Enter employee #:" << endl;
cin >> employeeNum;
// While loop that runs while employee number is not 0 (sentinel)
while (employeeNum != 0)
{
// adds 1 to count to keep track of loop and number of employees entered
count += 1;
// Asks for and receives gross pay and then begins to accumulate a total.
cout << "Enter gross pay for employee " << count << endl;
cin >> grossPay;
grossTotal += grossPay;
// Asks for and receives sales tax and then begins to accumulate a total.
cout << "Enter state tax for employee " << count << endl;
cin >> stateTax;
stateTotal += stateTax;
// Asks for and receives federal tax and then begins to accumulate a total.
cout << "Enter federal tax for employee " << count << endl;
cin >> federalTax;
federalTotal += federalTax;
// Asks for and receives FICA withholdings and then begins to accumulate
// a total.
cout << "Enter FICA withholdings for employee " << count << endl;
cin >> ficaWithhold;
ficaTotal += ficaWithhold;
// computations for netPay and netTotal.
netPay = grossPay - (stateTax + federalTax + ficaWithhold);
netTotal += netPay;
// Asks for next employee # before loop restarts. If 0, loop will end.
cout << "Enter next employee #" << endl;
cin >> employeeNum;
}
// end of loop
// sets output formatting to 2 decimal places.
cout << setprecision(2) << fixed << endl;
// Output table headers.
cout << "Gross Pay: \t State Tax: \t Federal Tax: \t ";
cout << "FICA Withholdings: \t Net Pay:" << endl;
// Output data with proper tabular formatting.
cout << "$" << grossTotal << "\t $" << stateTotal << "\t\t $";
cout << federalTotal << "\t\t $" << ficaTotal << "\t\t\t\t $";
cout << netTotal << endl;
return 0;
}