The gross pay cannot be less than the withholdings. My goal is to set that back up where the "do" is
#include <iostream>
using namespace std;
int main ()
{
double userChoice, employeeNumber, grossPay, stateTax, federalTax, ficaWithholdings,
netPay, totalGrossPay, totalStateTax, totalFederalTax, totalFicaWithholdings, totalNetPay; //Declares variables
cout<<"\t\tMENU\n"; //Menus screen
cout<<"----------------------------------------------\n";
cout<<"1) Payroll Report \n";
cout<<"2) Salesbar Chart \n";
cout<<"3) Quit\n";
cout<<endl;
cout<<"Enter choice: ";
cin>>userChoice;
cout<<endl;
while(userChoice == 1) //Executing payroll report
{
cout<<"Enter the employee number (0 to quit): ";
cin>>employeeNumber;
if (employeeNumber == 0)
{
cout<<"Program terminated";
return 0;
}
while(employeeNumber < 0)
{
cout<<"Error, number can't be negative. \n"; //input validation
cout<<"Enter the employee number: ";
cin>>employeeNumber;
cout<<"\n";
}
//-------------------------------------------------
do {
cout<<"Enter the gross pay: $"; //Gets gross pay
cin>>grossPay;
while(grossPay < 0)
{
cout<<"Error, number can't be negative. \n"; //Input validation
cout<<"Enter the gross pay: $";
cin>>grossPay;
}
//------------------------------------------------
cout<<"Enter the state tax: $";
cin>>stateTax; //gets state tax
while(stateTax < 0 || stateTax > grossPay) //Input Validation
{
cout<<"Error, number can't be negative, or greater than gross pay \n";
cout<<"Enter the state tax: $";
cin>>stateTax;
//while(stateTax > grossPay)
/*{
cout<<"Error, number can't be greater than the gross pay. \n";
cout<<"Enter the state tax: $";
cin>>stateTax;
}*/ //documented out because was causing errorsin code
}
//----------------------------------------------
cout<<"Enter the federal tax: $";
cin>>federalTax; //gets federal tax
while(federalTax < 0 || federalTax > grossPay) //Input valdation for federal tax
{
cout<<"Error, number can't be negative, or greater than gross pay \n";
cout<<"Enter the federal tax: $";
cin>>federalTax;
/*while(federalTax > grossPay)
{
cout<<"Error, number can't be greater than the gross pay. \n";
cout<<"Enter the federal tax: $";
cin>>federalTax;
}*/
}
//-----------------------------------------------
cout<<"Enter the FICA witholdings: $";
cin>>ficaWithholdings; //gets fica
while(ficaWithholdings < 0 || ficaWithholdings > grossPay) //input validation for fica
{
cout<<"Error, number can't be negative, or greater than gross pay \n";
cout<<"Enter the FICA Withholdings: $";
cin>>ficaWithholdings;
//while(ficaWithholdings > grossPay)
/*
{
cout<<"Error, number can't be greater than gross pay. \n";
cout<<"Enter the FICA Withholdings: $";
cin>>ficaWithholdings;
}*/
}
cout<<endl;
//------------------------------------------------
netPay = grossPay - (stateTax + ficaWithholdings + federalTax);
**if ((stateTax + ficaWithholdings + federalTax) > grossPay) //Gross pay cannot be less than taxes combined
{
cout<<"Error, witholdings cannot exceed gross pay.\n"; //*******Where I'm having trouble******
cout<<"Reenter data: \n";
cout<<"Enter the employee number (0 to quit): ";
cin>>employeeNumber;
}**
totalGrossPay = totalGrossPay + grossPay; //Calculations
totalStateTax = totalStateTax + stateTax;
totalFederalTax = totalFederalTax + federalTax;
totalNetPay = totalNetPay + netPay;
totalFicaWithholdings = totalFicaWithholdings + ficaWithholdings;
cout<<"Enter the employee number (0 to quit): "; //Asks for employee number to loop again
cin>>employeeNumber;
}
while(employeeNumber > 1); //end of do-while
Aucun commentaire:
Enregistrer un commentaire