Cannot order the numbers in ascending order

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

int main(){
	bool n=true;
	int i=0;
		for (int num1=1 ; num1<50 ; num1++){
			for (int num2=2 ; num2<50 ; num2++){
				for (int num3=3 ; num3<50 ; num3++){
					for (int num4=4 ; num4<50 ; num4++){
						for (int num5=5 ; num5<50 ; num5++){
							for (int num6=6 ; num6<50 ; num6++){
				
				if (num2 <= num1)
					n=false;
				if (num3 <= num2)
					n=false;
				if (num4 <= num3)
					n=false;
				if (num5 <= num4)
					n=false;
				if (num6 <= num5)
					n=false;
				i = i+1;
				if (n=true)
					cout<<i<<". "<<num1<<" , "<<num2<<" , "<<num3<<" , "<<num4<<" , "<<num5<<" , "<<num6<<"\n";
				else (n=true);
						}
					}
				}
			}
		}
	}
	
	return 0;
}


It is a program for generating all the combinations of a gamble in Hong Kong.
It is called Mark Six.
A combination consist 6 numbers ranging from 1 to 49.
No repeating numbers.
I want to make the numbers ordering in ascending order.
But I fail.
No errors existing in the program.
Just cannot order the numbers in ascending order.
What's the problem?
I don't think it's a good idea to create so many nested for loops. Otherwise, I think you should write this inside most deeply nested for loop:

1
2
3
if (num1 < num2 && num2 < num3 && num3 < num4 && num4 < num5 && num5 < num6) {
cout << i /*etc etc*/;
}


You can remove else statement and that bool variable.

But I think you should do everything differently. Make it so that the next number only counts from where previous number is... Count num2 from "num1+i" while "num1+i <= 49. Do the same for num3 (loop while "num2+i <= 49" and so forth. "i" being variable initialized in each loop (int i=1) except the top-most loop.

Otherwise the program has to loop 49^6 times!
I've written the code, but the program itself is useless. There are so many different combinations that it didn't get to
1 3 X X X X
after about a minute and it most probably wouldn't for some time. The last combination to output is
44 45 46 47 48 49
, so you can imagine how long it would take to get there.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main() {
	for (int num1=1; num1<=49; num1++) {
		for (int num2=num1+1; num2<=49; num2++) {
			for (int num3=num2+1; num3<=49; num3++) {
				for (int num4=num3+1; num4<=49; num4++) {
					for (int num5=num4+1; num5<=49; num5++) {
						for (int num6=num5+1; num6<=49; num6++) {
							cout << num1 << " " << num2 << " " << num3
								<< " " << num4 << " " << num5 << " "
								<< num6 << "\n";
						}
					}
				}
			}
		}
	}
	cin.get();
	return 0;
}
Thank you very much.

It may be useless.
and I just want to learn from it.

Thx!
Topic archived. No new replies allowed.