Lottery Generator

Pages: 12
The for loop in randomNumber should work for your needs. Then, compare each element in user[] and lottery[], and see if they're equal.

Oh... by the way... your code won't work as expected.

-Albatross
I got it to work. Can you please look it over? Thanks.

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

//Function Prototypes
void getUserNumber(int [], int);
void randomNumber(int [], int);

int main()
{

	const int SIZE = 5;
	int user[SIZE];
	int lottery[SIZE];

	//Get user numbers
	getUserNumber(user, SIZE);
	cout << "User Numbers: \n";
	for (int i = 0; i < 5; i++)
		{
			cout << user[i] << " ";
		}
	//Get lottery numbers
	cout << "\n\n";
	cout << "Lottery Numbers: \n";
	randomNumber(lottery, SIZE);
	cout << "\n";

	//Check for Grand Prize Winner
	for (int x = 0; x < 1; x++)
	{
		if (user[x] == lottery[x])
			cout << "You are the Grand Prize Winner!!!";
		else
			cout << "I'm sorry you are not a winner.  Thank you for playing\n";
		}
	
	return 0;
}

void randomNumber(int lottery[], int size)
{
	srand((unsigned)time(0));

	for (int number = 0; number < size; number++)
	{
		lottery[number] = 1 + rand() % 9;
		cout << lottery[number] << " ";
	}
	 
}

void getUserNumber(int user[], int size)
{
	
	//Get user numbers
	for (int userNum = 0; userNum < size; userNum++)
		{
			cout << "Enter your numbers " << (userNum + 1) << ": ";
			cin >> user[userNum];
		}

}
http://cplusplus.com/doc/tutorial/functions2/

Check your functions. They will not do anything to lottery and user's values in main.

-Albatross
closed account (Lv0f92yv)
Look at your for loop:
1
2
3
4
5
6
7
for (int x = 0; x < 1; x++)
	{
		if (user[x] == lottery[x])
			cout << "You are the Grand Prize Winner!!!";
		else
			cout << "I'm sorry you are not a winner.  Thank you for playing\n";
	}


As it stands, it only checks the first number in the sequence. Is this what you intend?

@Albatross, I compiled and ran his code, it seems that the users and lottery's values have changed in main... Why do you think this will not happen?
Topic archived. No new replies allowed.
Pages: 12