Could I get some direction on this code please.

For some reason I can not get it past 00-000 when I use:
while (ii<=9);

I'm getting closer with:
while (ii++<=9);
but it runs this: 10000-999,

This one is really close:
while (ii!=0);
but it runs to 10-000,,seems like its still iterating in the background though.

I would like to have the numbers reach 99-999...I'm sure it's something simple I'm overlooking.

Thanks in advance.

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 #include<iostream>
#include<Windows.h>
using namespace std;

int main()
{
	int tickets2 = 0;
	double doll2 = 0;
	int ii, jj, kk, ll, mm;
	

cout<<"\n\nPlease wait, the combinations are caclculating...\n\n";
cout<<"*************************************************\n";
cout<<"*                                               *";
cout<<"\n*************************************************";

	for (ii=0; ii<=9; ii++){
	for (jj=0; jj<=9; jj++){
	for (kk=0; kk<=9; kk++){
	for (ll=0; ll<=9; ll++){		
	for (mm=0; mm<=9; mm++){
		


HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position;

int aa = 20;
int bb = 5;

do
{
position.X = aa;
position.Y = bb;
SetConsoleCursorPosition(screen,position);
Sleep(1/20);

cout<<ii<<" "<<jj<<'-'<<kk<<" "<<ll<<" "<<mm<<endl;

}while (ii!=0 && ii<=9);

cout<<endl;

}}}}}
	tickets2 = ii*jj*kk*ll*mm;
	cout<<"\nThe number of tickets is: "<< tickets2 << endl;
	doll2 = tickets2 *.5;
	cout<<"The cost for "<< tickets2 <<" tickets is: $"<< doll2 <<endl;
	cout<< endl;

	system("pause");
		return 0;
		}
well for one its pointless to use the for loop like that on lines 17-21.
just do something like this
1
2
3
4
5
    int i = 0;
    do {
        cout << i << i << "-" << i << i << i << endl;
        i++;
    } while(i < 10);

that is if you are trying to do what it looks like you are trying to achieve.
but that will only get results of 00-000, 11-111, 22-222, ect.... and not like 00-000, 00-001, 00-002, ect..for that you would have to do something like
1
2
3
4
5
6
7
8
9
10
11
12
13
int i = 0, j = 0, k = 0, l = 0, m2  = 0;
    do {
        for(unsigned int n = 0; n < 1000; n++){
            cout << i << j << "-" << k << l << m2 << endl;
            if(m2 != 9) m2++;
            if(m2 == 9 && l != 9){ l++; m2 = 0; }
            if(l == 9 && k != 9){ k++; l = 0; }
            if(k == 9 && j != 9){ j++; k = 0; }
            if(j == 9 && i != 9){ i++; j = 0; }
            if(i == 9 && j == 9 && k == 9 && l == 9 && m2 == 9) { cout << i << j << "-" << k << l << m2 << endl; break; }
        }
        if(i == 9 && j == 9 && k == 9 && l == 9 && m2 == 9) break;
    } while(i < 10);

probably not the prettiest solution
giblit,

Thanks for the fast reply,

The second code is closer to what I am doing, Thanks.
I liked how you used your for loop.
Many props :)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

#include<iostream>
#include<Windows.h>
using namespace std;

int main()
{

cout<<"\n\nPlease wait, the combinations are caclculating...\n\n";
cout<<"*************************************************\n";
cout<<"*                                               *";
cout<<"\n*************************************************";

int i = 0, j = 0, k = 0, l = 0, m2  = 0;
	
	HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD position;
	int tickets2 = 0;
	double doll2 = 0;
	

    do {
		for(unsigned int n = 0; n < 1000; n++)
			{
			int aa = 20;
			int bb = 5;
			position.X = aa;
			position.Y = bb;
			SetConsoleCursorPosition(screen,position);
			Sleep(1/250);

			cout << i <<" "<< j << " - " << k <<" "<< l <<" "<< m2 << endl;
           
			if(m2 != 9) m2++;
			if(m2 == 9 && l != 9){ l++; m2 = 0; }
			if(l == 9 && k != 9){ k++; l = 0; }
			if(k == 9 && j != 9){ j++; k = 0; }
			if(j == 9 && i != 9){ i++; j = 0; }
			if(i == 9 && j == 9 && k == 9 && l == 9 && m2 == 9)
			{}}
			if(i == 9 && j == 9 && k == 9 && l == 9 && m2 == 9) break;
		}while(i < 10);

	tickets2 = i*j*k*l*m2;
	cout<<"\n\nThe number of tickets is: "<< tickets2 << endl;
	doll2 = tickets2 *.5;
	cout<<"The cost for "<< tickets2 <<" tickets is: $"<< doll2 <<endl;
	cout<< endl;

	system("pause");
		return 0;
		}
Last edited on
Topic archived. No new replies allowed.