The while Statement! I need some help!

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	//declare variables
	
	int storePayroll = 0;
	int totalPayroll = 0;
	int storeNum = 0;


	//set up while loop
	while (storeNum < 3)
	{
		
		//set increment to increase by one each time
		storeNum++;
		
		cout << "Enter the store payrole: $";
		cin >> storePayroll;

		//calculation
		totalPayroll+=storePayroll;

	} //end while
	
	cout << "Total payroll: $" << totalPayroll << endl;


system ("pause");
return 0; 
}//end main 


THANK YOU WHOEVER REPLIES
Last edited on
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.
Last edited on
For your second point wouldn't i need to have it set to 1?

By the way, there are a lot of errors that i see as far as my wording goes. I just updated the code.
And I noticed that I ask for the store number but then I set the store number to automatically increase by one each time. This isn't necessary but I'm not sure how to do otherwise.
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.
Alright SWEET. I got it! Thanks you!!
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.

Like;
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*

Topic archived. No new replies allowed.