/* Payroll Report - This program displays a weekly payroll report. A loop
in the program asks the user for the employee number, gross pay, state
tax and federal tax, and FICA withholdings. The loop will terminate when
0 is entered, the program displays totals for gross pay, state tax,
federal tax, FICA withholdings, and net pay.
Input Validation: No negative numbers for any of the items entered are
accepted. No values for state, federal or fica withholdings that are
greater than the gross pay are accepted. If the sum of state tax +
federal tax + FICA withholdings for any employee is greater than gross
pay, an error message is printed, asking the user to reenter the data
for the employee. */
#include "Utility.h"
int main()
{
/* Constant: QUIT */
const int QUIT = 0;
/* Variable: Employee number, Choice */
int employeeNumber = 0,
choice = 1;
/* Variables: Gross pay, State tax, Federal tax, FICA withholdings, Total
gross pay, Total state tax, Total federal tax, total FICA withholdings,
Total Tax Amount, Net pay */
double grossPay = 0,
stateTax = 0,
federalTax = 0,
FICAWithholdings = 0,
totalGrossPay = 0,
totalStateTax = 0,
totalFederalTax = 0,
totalFICAWithholdings = 0,
totalTax = 0,
totalNetPay = 0;
/* Display: Information */
cout << "\t\tPAYROLL REPORT\n\n"
<< "This program allows you to generate an automated payroll\n"
<< "report for your employee(s). To proceed, you must provide\n"
<< "\n\t* The employee number (or I.D.)\n"
<< "\t* His or her gross pay\n"
<< "\t* The applicable state stax (effective tax rate!)\n"
<< "\t* The federal tax (effective tax rate!)\n"
<< "\t* The FICA withholdings.\n\n"
<< "Please proceed.\n";
/* Do While loop: While the user does not enter 0 to quit, this loop
will iterate */
do
{
/* Nested While loop::Input::Input Validation: While any of the
numbers the user enters is not -1, or choice is not quit, this
loop will iterate */
while (!(employeeNumber < 0 || grossPay < 0 || stateTax < 0 ||
federalTax < 0 || FICAWithholdings < 0 || choice == QUIT))
{
/* Ask for the employee number, gross pay, state tax, federal
tax and FICA withholdings */
cout << "\nPlease enter the employee number (or I.D.): ";
cin >> employeeNumber;
/* Nested While loop::Input Validation: While employee number
is lower than, or equal to 0, this loop will iterate */
while (employeeNumber <= 0)
{
/* Display: An error message */
cout << "An error occured: The number you entered was\n"
<< "negative. All numbers must be positive.\n"
<< "Employee Number: 42124\n";
/* Ask again */
cout << "Please enter the employee number (or I.D.): ";
cin >> employeeNumber;
}
cout << "\nGross Pay: $ ";
cin >> grossPay;
/* Nested While loop::Input Validation: While gross pay
is lower than, or equal to 0, this loop will iterate */
while (grossPay <= 0)
{
/* Display: An error message */
cout << "\nAn error occured: The number you entered was\n"
<< "negative. All numbers must be positive.\n"
<< "Gross Pay: $27500.00\n";
/* Ask again */
cout << "Gross Pay: $ ";
cin >> grossPay;
}
cout << "State Tax: % ";
cin >> stateTax;
/* Nested While loop::Input Validation: While state tax
is lower than, or equal to 0, this loop will iterate */
while (stateTax <= 0)
{
/* Display: An error message */
cout << "\nAn error occured: The number you entered was either\n"
<< "negative, or higher than the Marginal state tax rate\n"
<< "of 4.00%.\n";
/* Ask again */
cout << "State Tax: % ";
cin >> stateTax;
}
cout << "Federal Tax: % ";
cin >> federalTax;
/* Nested While loop::Input Validation: While state tax
is lower than, or equal to 0, this loop will iterate */
while (federalTax <= 0)
{
/* Display: An error message */
cout << "\nAn error occured: The number you entered was either\n"
<< "negative, or higher than the Marginal federal tax rate\n"
<< "of 15.00%.\n";
/* Ask again */
cout << "Federal Tax: % ";
cin >> federalTax;
}
cout << "FICA Withholdings: % ";
cin >> FICAWithholdings;
/* Nested While loop::Input Validation: While state tax
is lower than, or equal to 0, this loop will iterate */
while (FICAWithholdings <= 0)
{
/* Display: An error message */
cout << "\nAn error occured: The number you entered was either\n"
<< "negative, or higher than the Marginal FICA tax rate\n"
<< "of 7.65%.\n";
/* Ask again */
cout << "FICA Withholdings: % ";
cin >> FICAWithholdings;
}
/* Calculations: State tax, Federal tax, FICA withholdings, Total
tax amount, Total net pay */
totalStateTax = (grossPay * stateTax) / 100;
totalFederalTax = (grossPay * federalTax) / 100;
totalFICAWithholdings = (grossPay * FICAWithholdings) / 100;
totalTax = (totalStateTax + totalFederalTax + totalFICAWithholdings);
totalNetPay = grossPay - totalTax;
/* Calculation Validation::If statement: If, for whatever reason,
the sum of state tax + federal tax + and FICA withholdings is
greater than gross pay, an error message will be displayed */
if (totalTax > grossPay)
{
/* Display: Error message */
cout << "\nOh no, an error occured! The total tax can not be.\n"
<< "greater than the gross pay. Please enter data for\n"
<< "employee: " << employeeNumber << " once more.\n";
}
else
{
/* Display: The formatted report */
cout << fixed << showpoint << setprecision(2);
cout << "\nPayroll Report for Employee: " << employeeNumber << "\n";
cout << "-----------------------------------------------------------\n";
cout << "Gross Pay Amount:\t\t\t$ " << setw(8) << left << grossPay
<< endl;
cout << "-----------------------------------------------------------\n";
cout << "Total State Tax:\t\t\t$ " << setw(8) << right << totalStateTax
<< endl;
cout << "Total Federal Tax:\t\t\t$ " << setw(8) << right << totalFederalTax
<< endl;
cout << "Total FICA Withholdings:\t\t$ " << setw(8) << right << totalFICAWithholdings
<< endl;
cout << "Total Tax Amount:\t\t\t$ " << setw(8) << right << totalTax
<< endl;
cout << "------------------------------------------------------------\n";
cout << "Total Net Pay:\t\t\t\t$ " << setw(8) << left << totalNetPay
<< "\n\n";
/* Ask the user if he or she wishes to create another report */
cout << "Enter 0 to Quit or 1 to create another report: ";
cin >> choice;
}
}
} while (choice != QUIT);
pauseSystem();
return 0;
}
Monday, December 19, 2016
Programming Challenge 5.15 - Payroll Report
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment