I have a program that needs to calculate the total for three stores payrolls.
Inputs would be the three stores payrolls
Output would be the total of all three
I HAVE to use the while statement.
I have also read the articles on the while statement on here and on other sites. I'm having trouble because every site I've seen so far has only been giving examples of numbers(like counting down or repeating a statement so many times).
Any pointers or while statements that actually have a process with inputs would be greatly appreciated.
Here's my code. I know i have flaws in this all over, please point them out! :P
int storePayroll = 0;
int totalPayroll = 0;
int storeNum = 0;
//set up while loop
while (storeNum < 3)
//set increment to increase by one each time
cout << "Enter the store payrole: $";
cin >> storePayroll;
} //end while
cout << "Total payroll: $" << totalPayroll << endl;
From what you described, the only input you need is the store's payroll. You got that covered (actually it's +=, not =+), now you need to figure out how to keep the program running long enough for all 3 stores to key in their input.
storeNum starts at 0, so your current condition for the while loop will always return false. What are you going to change to make the condition true, and actually enter the while loop?
After that's done, you already have the way to get out of the loop. There's just a misplacement of that line.
You don't want to ask the user for the store number at all. Also, your while condition is the wrong way (should be storeNum < 3). storeNum needs to start at 0 and increment by 1 each time. This way, the loop will run 3 times. All the loop should do is get the storePayroll and increment totalPayroll.
One more thing. It's not this problem but it's kind of related. How would I update the final cout << statement to update as in if the ending were to state the storeNum and the storePayroll respectively.
The payroll for store 1 is a
The payroll for store 2 is b
The payroll for store 3 is c
*while using the while statement*