Problem statement: Write a program that displays a weekly payroll report. A loop
ID: 3544821 • Letter: P
Question
Problem statement: Write a program that displays a weekly payroll report. A loop in the
program should ask the user to enter the following data [10 points]:
? Employee number
? Number of hours worked
? Hourly pay rate
? Percentage to be withheld for state income tax
? Percentage to be withheld for federal income tax
? Percentage to be withheld for FICA
The loop will terminate when 0 is entered for the employee number [10 points]. The program
should calculate and display the following data for each [30 points]:
? Employee number
? Gross pay (the number of hours worked multiplied by the hourly pay rate)
? State income tax withholdings (gross pay multiplied by state income tax percentage)
? Federal income tax withholdings (gross pay multiplied by federal income tax
percentage)
? Federal Insurance Contributions Act (FICA) withholdings (gross pay multiplied by
FICA percentage)
? Net pay (the gross pay minus state income tax, federal income tax, and FICA)
Input Validation: Do not accept negative numbers for any of the items entered [10 points]. If
the sum state tax + federal tax + FICA withholdings for any employee is greater than gross pay,
print an error message and ask the user to re?enter the data for that employee [10 points]. Test
your program with the following test cases. Make sure you don
Explanation / Answer
#include <iostream>
using namespace std;
int main ()
{
// The infinite while loop which stops executing when you enter 0 for employee number
while(1){
int empNum,hrsWorked,payRate;
float stateTaxp, federalTaxp, ficaTaxp;
float grossPay, sTax, fTax, ficaTax, netPay;
cout << " Enter the employee number :";
cin >> empNum;
if (empNum == 0)
break; // come out of the infinite while loop if the employee number is 0
//Validation - to check negative inputs
while (empNum < 0)
{
cout << " Please enter a positive integer for employee number :";
cin >> empNum;
}
cout << " Number of hours worked :";
cin >> hrsWorked;
//Validation - to check negative inputs
while (hrsWorked < 0)
{
cout << " Please enter a positive integer for Hours Worked :";
cin >> hrsWorked;
}
cout << " Hourly Pay Rate :";
cin >> payRate;
//Validation - to check negative inputs
while (payRate < 0)
{
cout << " Please enter a positive integer for hourly pay rate :";
cin >> payRate;
}
cout << " Percentage to be withheld for state income tax :";
cin >> stateTaxp;
//Validation - to check negative inputs
while (stateTaxp < 0)
{
cout << " Please enter a positive integer for state tax percentage :";
cin >> stateTaxp;
}
cout << " Percentage to be withheld for federal income tax :";
cin >> federalTaxp;
//Validation - to check negative inputs
while (federalTaxp < 0)
{
cout << " Please enter a positive integer for federal tax percentage :";
cin >> federalTaxp;
}
cout << " Percentage to be withheld for FICA :";
cin >> ficaTaxp;
//Validation - to check negative inputs
while (ficaTaxp < 0)
{
cout << " Please enter a positive integer for FICA tax percentage :";
cin >> ficaTaxp;
}
grossPay = hrsWorked * payRate; // To cacl the gross pay - Number of hours worked multiplie by hourly pay rate
sTax = grossPay * (stateTaxp / 100); // calc state tax
fTax = grossPay * (federalTaxp / 100); // calc federal tax
ficaTax = grossPay * (ficaTaxp / 100); // calc FICA tax
if (sTax + fTax + ficaTax > grossPay) // check if grosspay is less than taxes
{
cout << " The Gross pay should not be less than the sum of all taxes. Please re-enter the details for the below employee";
}
else
{
netPay = grossPay - (sTax + fTax + ficaTax); // calc net pay
cout << " ****************************************************";
cout << " Employee number :" << empNum;
cout << " Gross Pay :" << grossPay;
cout << " State Income Tax Withholdings :" << sTax;
cout << " Federal Income Tax Withholdings :" << fTax;
cout << " FICA Withholdings :" << ficaTax;
cout << " Net Pay : " << netPay;
cout << " ****************************************************";
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.