C++ loterry

Hey guys, I need you help. i wrote a lotery code but it doesent work korekt and I cant find the mistake. It doesent outpu the numbers. Here is the code:

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <iomanip>

using namespace std;

const int ANZ = 6;

struct lottoTipp
{
	int tipp[6];
};

int main()
{
	char input;
	int anz = 0;
	lottoTipp *pFeld = 0;

	while (true)
	{
		char comand = 'w';

		cout << "\tWhat do you want to do?\n\n";
		cout << "\tgenerate new numbers (n/N)\n";
		cout << "\tPrint out the numbers (a/A)\n";
		cout << "\tEscape (b/B)\n";
		cin >> input;

		switch (input)
		{
		case 'n':
		case 'N':

			system("cls");
			srand(time(0));
			pFeld = new lottoTipp[anz];

			cout << "\tPress w to generate new numbers: ";
			cin >> comand;

			if (input == true)
			{
				for (int i = 0; i < ANZ; i++)
				{
					for (int j = 0; j < 6; j++)
					{
						pFeld[i].tipp[j] = rand() % 49 + 1;
					}
				}
			}
			break;
			cout << "\tInitialization successfull.\n\n";
			

		case 'a':
		case 'A':
			for (int i = 0; i < anz; i++)
			{
				for (int j = 0; j < 6; j++)
				{
					cout << right << setw(5) << pFeld[i].tipp[j];
				}
				cout << '\n';
			}
		}
	}

	return 0;
}


I dont understand why it doesen print out the numbers. Please help me with that
Last edited on
Its because your for loop never runs.

for (int i = 0; i < ANZ; i++) // ANZ is equal to 0.
Yes thanks for the tipp. That was the first mistake but it doesen solve the problem
Your other anz aswel... int anz = 0; // why is this equal to 0?

pFeld = new lottoTipp[anz]; // You're creating an empty array

I suggest you learn how to debug. It'll save you many times and is equally as important as coding.
Last edited on
Sorry I dont get it. I changed now anz to 1 and he print me one line out. But the numbers are negative and over 84000000 size. And all 6 are the same
Works fine for me.

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
54
55
56
57
58
59
60
61
62
const int ANZ = 1;

struct lottoTipp
{
	int tipp[6];
};

int main()
{
	char input;
	int anz = 1;
	lottoTipp *pFeld = 0;

	while (true)
	{
		char comand = 'w';

		cout << "\tWhat do you want to do?\n\n";
		cout << "\tgenerate new numbers (n/N)\n";
		cout << "\tPrint out the numbers (a/A)\n";
		cout << "\tEscape (b/B)\n";
		cin >> input;

		switch (input)
		{
		case 'n':
		case 'N':

			system("cls");
			srand(time(0));
			pFeld = new lottoTipp[anz];

			cout << "\tPress w to generate new numbers: ";
			cin >> comand;

			if (input = true)
			{
				for (int i = 0; i < ANZ; i++)
				{
					for (int j = 0; j < 6; j++)
					{
						pFeld[i].tipp[j] = rand() % 49 + 1;
					}
				}
			}
			break;
			cout << "\tInitialization successfull.\n\n";


		case 'a':
		case 'A':
			for (int i = 0; i < anz; i++)
			{
				for (int j = 0; j < 6; j++)
				{
					cout << right << setw(5) << pFeld[i].tipp[j];
				}
				cout << '\n';
			}
		}
	}
}
Thank you finally. I had two mistakes. The first one was that ANZ anz both were equel to 0 and the second one was if(input == true). Now it works.

Thanks for you help. I really apriciat it.
Last edited on
Oh yea, I missed that part, weird that my compiler didint say shit. Oh well, glad I could help!

Happy Coding
Topic archived. No new replies allowed.