I wrote this programme but what two numbers you choose exit it?
can you guess just by looking? Because I can't :(

#include <iostream>
#include <string>

using namespace std;

int main()
{

	bool aHo = true;
	int a = 0;
	int b = 0;
	
	while(aHo)
	{
	cout << "Enter Number one: ";
	cin >> a;
	cout << endl;
	cout << "Enter NUmber two: ";
	cin >> b;
	cout << endl;
	
	for (int i = 0; i< 2; i++)
		for (int j = 0;  j < 2; j++)
			for (int z = 0; z < 2; z++)
				for (int v = 0; v < 2; v++)
					cout << a++ << " " << ++b << " " << ++a << " " << b++ << endl;
	a++;
		if (a == 30 && b == 34)
			aHo = false;
	}


	system("PAUSE");
}

If you type in 0 and 0, what are the value of a&b at the end of the while loop? That should help you figure out the two numbers to enter.

As can be observed, the cout statement is exected 2*2*2*2 = 16 times. Each time both a and b gets incremented twice.
Therefore they are incremented 32 times. a gets incremented once more. That makes a increment 33 times and b 32 times.
You need to enter such 'a' tht it becomes 30 after 33 increments and such a 'b' tht it becomes 34 after 32 increments.

Ah so to find how many times it goes through a loop you multiply all of them, cool thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.