So everything in my program seems to be working fine up to the point when there's an error within one of the inputted variables.
Ex. gross pay. I need to re-input the employee number, but it keeps giving the one already given at the start. I'm not sure how to make it possible to re-input the employee number instead of having it already outputted. I can only use loops and if statements. I can't do arrays.
Please review below code
{
const int QUIT = 0, NO_NEG = 0;
int empNum = 1;
double grossPay, fedWith,
stateWith, ficaWith, sum,
totalGross = 0, totalFed = 0,
totalState = 0, totalFica = 0,
netPay, totalNetPay = 0;
cout << "Enter the following information:\n\n"
<< "Employee Number (0 to quit): ";
cin >> empNum;
while (empNum != QUIT)
{
do
{
cout << "Gross pay: ";
cin >> grossPay;
while (grossPay < NO_NEG)
{
cout << "Gross pay may not be less than zero.\n";
cout << "Re-enter Gross pay: ";
cin >> grossPay;
}
cout << "Federal Withholding: ";
cin >> fedWith;
while (fedWith < NO_NEG)
{
cout << "Federal witholding may not "
<< "be less than zero.\n";
cout << "Re-enter Federal Withholding: ";
cin >> fedWith;
}
cout << "State Withholding: ";
cin >> stateWith;
while (stateWith < NO_NEG)
{
cout << "State witholding may not "
<< "be less than zero.\n";
cout << "Re-enter State Withholding: ";
cin >> stateWith;
}
cout << "FICA Withholding: ";
cin >> ficaWith;
while (ficaWith < NO_NEG)
{
cout << "FICA witholding may not be less than zero.\n";
cout << "Re-enter FICA Withholding: ";
cin >> ficaWith;
}
sum = (stateWith + fedWith + ficaWith);
if (sum > grossPay)
{
cout << "\nERROR: Withholdings cannot"
<< " exceed gross pay.\n"
<< "\nPlease re-enter the data for this employee.\n"
<< "Processing the next employee:\n"
<< "\nEmployee Number (0 to quit): "
<< empNum << endl;
}
cout << "Processing the next employee:\n";
} while (sum > grossPay);
totalGross += grossPay;
totalFed += fedWith;
totalState += stateWith;
totalFica += ficaWith;
netPay = grossPay - sum;
totalNetPay += netPay;
cout << "Employee Number (0 to quit): ";
cin >> empNum;
}
cout << "Total Gross Pay: $ " << totalGross << endl
<< "Total Federal Tax: $ " << totalFed << endl
<< "Total State Tax: $ " << totalState << endl
<< "Total FICA: $ " << totalFica << endl
<< "Total Net Pay: $ " << totalNetPay << endl;
return 0;
}
"Processing the next employee"when that's not what the code is doing. You're also asking for input when the program isn't expecting any.