I'm not understanding why I'm getting so many errors. Is there a simpler way I can code this?
The payroll manager at Kenton Incorporated wants a program that allows him to enter an unknown number of payroll amounts for each of three stores: store 1, store 2, store 3. The program should calculate the total payroll and then display the result on the screen.
After checking your code, I realized that your code is written perfectly except for one thing, that you obviously have forgotten about it...
You have to put a condition between parenthesis right beside the while, because your while loop will stop when reaching the condition your stated!
cout << "Enter store id (1,2,3) or 0 to quit: ";
cin >> id;
if (id == 0) //sentinal value
{
break;
}
elseif (id == 1)
{
cout << "Enter payroll amount for store " << id;
cin >> tempPayroll;
totalPayroll = totalPayroll + tempPayroll;
store1 = store1 + tempPayroll;
}
elseif (id == 2)
{
cout << "Enter payroll amount for store " << id;
cin >> tempPayroll;
totalPayroll = totalPayroll + tempPayroll;
store2 = store2 + tempPayroll;
}
elseif (id == 3)
{
cout << "Enter payroll amount for store " << id;
cin >> tempPayroll;
totalPayroll = totalPayroll + tempPayroll;
store3 = store3 + tempPayroll;
}
Between this -
do
{
}while(id != 0);
That will run the loop until the user inputs the number 0, then the program will print out all of the information on the screen, and quit, just like you want it to.