Payroll Report Write a program that displays a weekly payroll report. A loop in
ID: 670296 • Letter: P
Question
Payroll Report
Write a program that displays a weekly payroll report. A loop in the program should
ask the user for the employee number, gross pay, state tax, federal tax, and FICA with-
holdings. The loop will terminate when 0 is entered for the employee number. After the
data is entered, the program should display totals for gross pay, state tax, federal tax,
FICA withholdings, and net pay.
Input Validation: Do not accept negative numbers for any of the items entered. Do
not accept values for state, federal, or FICA withholdings that are greater than the
gross pay. 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 reenter the data for
that employee.
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int employeeNum;
double netpay, gross, statetax, federaltax, fica;
do
{
cout << "Enter the employee number: ";
cin >> employeeNum;
cout<<"Enter the gross pay of the employee: ";
cin>>gross;
cout << "Enter state income tax: ";
cin >> statetax;
cout << "Enter federal income tax: ";
cin >> federaltax;
cout << "Enter FICA: ";
cin >> fica;
netpay = gross - statetax - federaltax - fica;
while (netpay<0 || statetax < 0 || federaltax < 0 || fica < 0||gross<0)
{
if(netpay<0){
cout<<"Invalid netpay as taxes are more than gross please reenter";
cout << "Enter the employee number: ";
cin >> employeeNum;
cout << "Enter percentage to be withheld for state income tax: ";
cin >> statetax;
cout << "Enter percentage to be withheld for federal income tax: ";
cin >> federaltax;
cout << "Enter percentage to be withheld for FICA: ";
cin >> fica;
netpay = gross - statetax - federaltax - fica;
}else{
cout << "Re-enter data must be greater than 0: " << endl;
cout << "Enter the employee number: ";
cin >> employeeNum;
cout << "Enter percentage to be withheld for state income tax: ";
cin >> statetax;
cout << "Enter percentage to be withheld for federal income tax: ";
cin >> federaltax;
cout << "Enter percentage to be withheld for FICA: ";
cin >> fica;
netpay = gross - statetax - federaltax - fica;
}
}
cout << "Payroll Report: ";
cout << "The Employee Number is: " << employeeNum << endl;
cout << "You gross pay is: $" << gross << endl;
cout << "Your state tax: $" << statetax << endl;
cout << "Your federal tax : $" << federaltax << endl;
cout << "Your FICA withholdings is: $" << fica << endl;
cout << "Your total netpay is: $" << netpay << endl;
}while(employeeNum != 0);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.