Nested loop?? Help please

Mar 27, 2013 at 6:07am
I need a program that allows a man to enter an unknown number of payroll amounts for each of three stores: Store 1, Store 2, and Store 3. The program should calculate the total payroll and then display the result on the screen.

here's my source code so far

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
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
	//declare variables
	double payrollAmount= 0.0;
	int storeNum = 1;
	double totalPayroll = 0.0 ;

			//set up while loop
			while (storeNum >= 1)
			{
		
				//set increment to increase by one each time
				storeNum++;
		
				cout << "Enter a payrole amount for a store: $";
				cin >> payrollAmount;

				//calculation
				totalPayroll+=payrollAmount;

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


system ("pause");
return 0; 


It's a lot similar like my other on I had posted but I have no idea how to tell it when to stop since the person could enter as many values as he would like.

I might need to use a sentinel value for the user to enter and also should i have it to where it states "Enter a payroll amount for store 1 (etc...): " or would that make it too complicated?

Could someone please show me how it's supposed to look like?

Thanks to all who reply!
Mar 27, 2013 at 6:39am
Hi, how about asking the user the number of input first? For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int storeNum = 0;
cout << "Enter the number of stores: ";
cin >> storeNum;

//set up while loop
int n = 0;
while (n < storeNum)
{
	//set increment to increase by one each time
	n++;
	cout << "Enter a payrole amount for a store: $";

        ......

}
Topic archived. No new replies allowed.