C++ Program Help. Lottery program.

Can someone help me with this code? Here are the directions to the assignment:

In this assignment you are to code a program that selects 10 random non-repeating positive numbers (the lottery numbers), takes a single input from the user and checks the input with the ten lottery numbers. The user wins if her input matches one of the lottery numbers.
What do you have so far?

We can help, but we can't do assignments for you.
Whats the easiest way to show you my code? Besides copy and paste. Sorry I am new to this site.
The easiest way is to copy and paste it into a reply but use the code tags. Click the button on the right of the reply box that looks like this <>.

Make sure all of your code is between the code tags. It'll be syntax highlighted and easier to spot problems.

Finally, only post the relevant code, rather than the whole program.
Here's what I have. Not sure why it isn't working. It works if the user loses but if the user wins it outputs nothing.

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

void initialize (int [], int, int);
int check (int [], int, int);
void draw (int[], int);
int entry ();
void printOut (int [], int, int);

int main(){
	const int size = 10;
	int wins [size];
	int initVal=-1;
	int guess;
	srand(time(NULL));

	initialize (wins, size, initVal);
	draw (wins, size);
	guess = entry ();
	int f = check (wins, size, guess);
	if (f==-1){
		cout << "You didn't win the lottery! Better luck next time..." << endl;
		printOut (wins, size, guess);
	}
	if (f==guess){
		cout << "You won the lottery!! Congratulations!!" << endl;
		printOut (wins, size, guess);
	}
}

void initialize (int a[], int n, int val){
	for (int i=0; i < n; i++)
		a[i] = val;
}

int check (int a[], int n, int value){
	for (int i=0; i < n; i++)
	{
		if (a[i] == value)
			return i;
	}

	return -1;
}

void draw (int a[], int n){
	int numSoFar = 0;
	while (numSoFar < n){
		int num = rand()%100;
		int e = check (a, n, num);
		if (e == -1){
			a[numSoFar] = num;
			numSoFar++;
		}
	}
}

int entry (){
	int userInput;
	cout << "Enter your guess <0-99>: ";
	cin >> userInput;
	return userInput;
}

void printOut (int a[], int n, int user){
	cout << "The winning numbers were: ";
	for (int i=0; i < n; i++)
		cout << a[i] << " ";
	cout << endl;
}
Topic archived. No new replies allowed.