C++ code for Weekly payroll report:
#include<iostream>
using namespace std;
int main()
{ // variables to store totals of amounts
int total_gross_pay=0;
int total_state_tax=0;
int total_federal_tax=0;
int total_FICA_withholdings=0;
while(1)
{
//variabls to store employee details
int employee_number;
int gross_pay;
int state_tax;
int federal_tax;
int FICA_withholdings;
cout<<"enter employee number : ";
cin>>employee_number;
// break the loop if employee number is 0
if(employee_number==0)
break;
// input for gross pay
label_1: cout<<"enter gross pay : ";
cin>>gross_pay;
if(gross_pay<0)
{
cout<<"invalid gross pay!! re-enter!!"<<endl<<endl;
// goto label_1 if constrains are not followed
goto label_1;
}
// input for state tax
label_2: cout<<"enter state tax : ";
cin>>state_tax;
if(state_tax<0 || state_tax > gross_pay)
{
cout<<"invalid state tax!! re-enter!!"<<endl<<endl;
goto label_2;
}
// input for federal tax
label_3: cout<<"enter federal tax: ";
cin>>federal_tax;
if(federal_tax<0 || federal_tax > gross_pay)
{
cout<<"invalid federal tax!! re-enter!!"<<endl<<endl;
goto label_3;
}
// input for FICA withholdings
label_4: cout<<"enter FICA withholdings : ";
cin>>FICA_withholdings;
if(FICA_withholdings<0 || FICA_withholdings > gross_pay)
{
cout<<"invalid FICA withholdings!! re-enter!!"<<endl<<endl;
goto label_4;
}
// check if gross pay is sufficient
if( gross_pay < federal_tax + state_tax + FICA_withholdings )
{
cout<< "gross pay is nsufficient!! re-enter the details !!"<<endl<<endl;
goto label_1;
}
total_gross_pay+= gross_pay;
total_federal_tax+= federal_tax;
total_state_tax += state_tax;
total_FICA_withholdings+= FICA_withholdings;
cout<<endl<<endl;
}//end of while loop
cout<<"----------------------------------------------"<<endl<<endl;
cout<<"Total gross pay : "<<total_gross_pay<<endl;
cout<<"Total federal tax : "<<total_federal_tax<<endl;
cout<<"Total state tax : "<<total_state_tax<<endl;
cout<<"Total FICA withholdings : "<<total_FICA_withholdings<<endl;
return 0;
}
Test run output:
Get Answers For Free
Most questions answered within 1 hours.