how to get 2 loops to loop together

This is my goal :Print out a table based on the number of days the user enters starting at one. List the pay for each day, the first days pay is a penny, but the pay doubles every day. Announce when the worker has earned $1000 and $1000000at the job.

I have both the loops i need but only the pay is being displayed..how can I get both to show?

int main ()

{
int day;
double n = .01;


cout << "Enter the starting day > ";
cin >> day ;

while (day < 1000) {

cout << day << " " ;
day++;

while (n< 1000)
{
cout << n << " \n";
n = n * 2;
}

cout << "1000!\n"; return 0;
}
return 0;

}
Please use [code][/code] tags.

Try getting rid of the return statement in the loop (cout << "1000!\n";// return 0; ). If you want to count from 0.01 in each iteration of the outer loop, you will need to set n to 0.01 in one of the loops as well.
Last edited on
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
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	bool showonce = 0; 	// show $1000 only once
	int days;		// number of days on job

	cout << "Enter starting day for job: ";
	cin >> days;
	
	for (double pay = .01; pay < 1000000; pay *= 2)
	{
		days++;		// increment days by one
		
		if (pay >= 1000 && !showonce)
		{
			cout << "\nYou made $1000 in "
			<< days << " days!" << endl;
			showonce = 1;
		}
	}

	cout << "You made $1000000 in " << days << " days!\n";
	cout << "Remember to share with carebear! ^^\n";

	return 0;
}
Last edited on
Topic archived. No new replies allowed.