I need help with my win counter

I wrote a code that situmaltes a lotto game and generate tickets. Now I need to check each ticket against the winining numbers and count how many numbers match and put them in categories.I wrote the code and it runs but it doesn't count the wins although I put the code for that

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  #include <iostream>

using namespace std;

int main()
{
	int min_ticket, max_ticket, ticknum;
	int n1, n2, n3, n4, n5, n6;
	bool megacount = false;
	int win_count = 0;
	int mega_five = 0, five = 0, mega_four = 0, four = 0, mega_three = 0 , three = 0;
	int	mega_two = 0, two = 0, mega_one = 0, one = 0 , mega = 0 , zero = 0;
	
	cout << "How many tickets do you want?:";
	cin >> ticknum; 

	for (int i = 0; i < ticknum; i++) // generates tickets
	{

		n1 = 1 + (rand() % 47);
		n2 = 1 + (rand() % 47);
		n3 = 1 + (rand() % 47);
		n4 = 1 + (rand() % 47);
		n5 = 1 + (rand() % 47);
		n6 = 1 + (rand() % 27);
		if (n1 != n2 && n1 != n3 && n1 != n4 && n1 != n5 &&
			n2 != n3 && n2 != n4 && n2 != n5 &&
			n3 != n4 && n3 != n5 && n4 != n5)
		{

			//cout << "Ticket #" << i << ' ' << n1 << " " << n2 << " " << n3 << " " << n4 << " " << n5 << " " << n6 << endl;
		}


		
	}

	for (int i = 0; i < 6 ; i++) // checks tickets wins
	{
		megacount = false;
		win_count = 0;

		
		
			if (n1 == 17 || n1 == 21 || n1 == 27 || n1 == 30 || n1 == 47)
			{
				win_count++;

			}
			if (n2 == 17 || n2 == 21 || n2 == 27 || n2 == 30 || n2 == 47)
			{
				win_count++;

			}
			if (n3 == 17 || n3 == 21 || n3 == 27 || n3 == 30 || n3 == 47)
			{
				win_count++;

			}

			if (n4 == 17 || n4 == 21 || n4 == 27 || n4 == 30 || n4 == 47)
			{
				win_count++;

			}
			if (n5 == 17 || n5 == 21 || n5 == 27 || n5 == 30 || n5 == 47)
			{
				win_count++;

			}
			if ( n6 == 24)
			{
				megacount = true;
			}

			//cout << "  " << win_count << " matching";
			//if (megacount)
				//cout << " and mega";
			//cout << endl;

			if (win_count == 5 && megacount)
			{

				mega_five++;
			}

			else if (win_count++ == 5)
			{
				five++;
			}

			else if (win_count == 4 && megacount)
			{
				mega_four++;
			}
			else if (win_count == 4)
			{
				four++;
			}

			else if (win_count == 3 && megacount)
			{
				mega_three++;
			}

			else if (win_count == 3)
			{
				three++;
			}

			else if (win_count == 2 && megacount)
			{
				mega_two++;
			}

			else if (win_count == 2)
			{
				two++;

			}

			else if (win_count++ == 1 && megacount)
			{
				mega_one++;

			}

			else if (win_count == 1)
			{
				one++;
			}
			else if (megacount)
			{
				mega++;
			}

			else if (win_count == 0)
			{
				zero++;
			}

			
		}

		
		cout << "\t\t\t Matching Numbers	Winning Tickets" << endl << endl << endl;
		cout << "\t\t\t 5 and mega			" << mega_five << endl << endl << endl;
		cout << "\t\t\t 5 Matching			" << five << endl << endl << endl;
		cout << "\t\t\t 4 and mega			" << mega_four << endl << endl << endl;
		cout << "\t\t\t 4 matching			" << four << endl << endl << endl;
		cout << "\t\t\t 3 and mega			" << mega_three << endl << endl << endl;
		cout << "\t\t\t 3 matching			" << three << endl << endl << endl;
		cout << "\t\t\t 2 and mega			" << mega_two << endl << endl << endl;
		cout << "\t\t\t 2 matching			" << two << endl << endl << endl;
		cout << "\t\t\t 1 and mega			" << mega_one << endl << endl << endl;
		cout << "\t\t\t 1 matching			" << one << endl << endl << endl;
		cout << "\t\t\t 0 Matching			" << zero << endl << endl << endl;



	return 0;
}



It has a lot of for loops I know but I don't know how to use mutiple functions and pass parameters. Anyways I think my loop in line 38 that is missing me up.I always have a problem with setting my loops,please help me. Thank you.
Last edited on

Line 17, the For loop will loop the required number of tickets yet each time it loops it will overwrite the last generated numbers - so basically you are not actually storing the tickets and only the last one generated.

You need to be looking at storing the lottery numbers in a array or ideally vector, then check their contents as necessary.
Topic archived. No new replies allowed.