Write lottery program using array!!!

Write a lottery program that generate 5 random numbers from 1-20 inclusive.
I had the whole things but it still giving me error. I am stuck.
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
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>

using namespace std;

int main()
{
	srand(time(NULL));

	int lottery[5] = { 0, 0, 0, 0, 0 }, count = 0, rand_lottery;
	bool isdup = false;

	cout << "Your Lottery:" << endl;

	while (count < 5)
	{
		int rand_lottery, i;
		rand_lottery = rand()%20 +1;
		i =  lottery[5]
		for (int i = 0; i < 5; i++);
		{
				if (lottery[i] == rand_lottery)
				{
					isdup = true;
				}
		}
		if (isdup == false)
		{ 
			lottery[count] = rand_lottery;
			count++;
		}
	}
	for (int i = 0; i < 5; i++)
	{
		cout << lottery[i] << " ";

		return (0);

	}
}

Last edited on

for (int i = 0; i < 5; i++);

yikes, that semi-colon. That's pretty common mistake though. :)

i = lottery[5]

i = lottery[5]; //semi-colon

My advice: Always check for the semi-colons. They're pretty nasty. heh
Last edited on
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
	srand(time(NULL));
	int lottery[10]; 
	for(int i=0; i<10; i++)
	{
		lottery[i] = rand()%20+1;
		for(int j=0; j<i; j++)
			if(lottery[i] == lottery[j])
			{
				i--;
				break;
			}
	}

cout << "Your Lottery:" << endl;
for(auto x: lottery)
	cout << x << " ";
cout << "\n\n";

return 0;
}
I add the semi colon but then it said my lottery[i] is unidentified identifier.
Huh? That's weird. I don't see any problem compiling here(Was it still the code above? :)). Btw, if you really want to be sure, try changing variable i to something else, because 'i' think that would be redundant.
Topic archived. No new replies allowed.