from the book \"starting out with c++ from control structures through objects.\"
ID: 3620844 • Letter: F
Question
from the book "starting out with c++ from control structures through objects." programming challenge 5.15= display a weekly payroll report. ask the user for the employee number, gross pay, sales tax, federal tax, and fica holdings. loop terminates when 0 is entered for the employee number. the output should be totals for gross pay, sales tax, fed tax, dica holdings and net pay.Your checks (you should have 5) for input validity should allow for users entering incorrect data more than once. In addition to the checks listed in the book, your program should also confirm that the gross pay is not negative. Your three checks for individual taxes should not allow the tax to be greater than the gross pay or to be a negative number. Your program should also count the number of employees entered. You may assume that at least one employee will be entered.
Explanation / Answer
please rate - thanks #include <iostream>using namespace std;
int main()
{int id,count=0;
int state,federal,FICA,gross,tgross=0,tstate=0,tfederal=0,tFICA=0;
cout<<"Enter employee id(0) to exit: ";
cin>>id;
while(id<0)
{cout<<"Invalid entry - re enter ";
cout<<"Enter employee id(0) to exit: ";
cin>>id;
}
while(id!=0)
{cout<<"Enter gross pay: ";
cin>>gross;
while(gross<0)
{cout<<"Invalid entry - re enter ";
cout<<"Enter gross pay: ";
cin>>gross;
}
do
{
cout<<"Enter state tax: ";
cin>>state;
while(state<0||state>gross)
{cout<<"Invalid entry - re enter ";
cout<<"Enter state tax: ";
cin>>state;
}
cout<<"Enter federal tax: ";
cin>>federal;
while(federal<0||federal>gross)
{cout<<"Invalid entry - re enter ";
cout<<"Enter federal tax: ";
cin>>federal;
}
cout<<"Enter FICA tax: ";
cin>>FICA;
while(FICA<0||FICA>gross)
{cout<<"Invalid entry - re enter ";
cout<<"Enter FICA tax: ";
cin>>FICA;
}
if(gross <state+federal+FICA )
{cout<<"Data being ignored gross pay < taxes ";
cout<<"reenter for employee number "<<id<<endl;
}
}while(gross <state+federal+FICA);
count++;
tgross+=gross;
tstate+=state;
tfederal+=federal;
tFICA+=FICA;
cout<<" Enter employee id(0) to exit: ";
cin>>id;
while(id<0)
{cout<<"Invalid entry - re enter ";
cout<<"Enter employee id(0) to exit: ";
cin>>id;
}
}
cout<<"Number of employees: "<<count<<endl;
cout<<"Total Gross Pay: $"<<tgross<<endl;
cout<<"Total Federal Tax: $"<<tfederal<<endl;
cout<<"Total State Tax: $"<<tstate<<endl;
cout<<"Total FICA: $"<<tFICA<<endl;
cout<<"Total Net Pay: $"<<tgross-tfederal-tstate-tFICA<<endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.