lottery simulator

Chaps I have written a lottery simulator ( I think ), but I can't help thinking that my logic is not correct on the conditional statement.
Basically int main() I use an bool array set to false and a random number gen which then sets the elements to true for the six numbers.
I then loop through the bool array and when true set that number to corrsponding element of the vector to store the numbers.

I pass this vector as const to a function that repeats the above but compares the vectors and if they are not the same the function runs again and checks const vect and so on and son on..

Can anyone put a learned eye over it for me please to check if my logic is correct - I'd really appreciate it!

The program is only to show my friends that they are bettor of buying a beer with the 2 quid lol !!!

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
164
165
166
167
168
169
170
171
172
173
174
  #include <iostream>
#include <cstdlib>
#include <ctime>
#include<vector>


using namespace std;

//function to return true if lotto win
bool lottoWin( const vector<int>& myLine,unsigned long int& numberOfDraws );


int main(void)
{
	int size = 6; // for vectors to compare
	bool lotterynumbers[59]; //array to store genertated numbers
	vector<int> myLine(size);//vector to store 6 numbers
	//integers to be used in for and while loops and amount of balls
	int num,line,numberofballs = 59;
	

	unsigned long int numberOfDraws = 0;// pass by value to increment in fuction
	
	srand( time(NULL) ); // randomise seed
	line = 1; //number of balls in a line set to one and inc to <=6


	//set all elements in lottrynumbers array to false
	for ( int i = 1; i <= numberofballs; i++)
		{
		lotterynumbers[i] = false;
		}

		
	//generate 6 random numbers and set that element to true	
	while( line <= size)
		{
		num = 1 + (rand() % 59);
		if ( !lotterynumbers[num] )
			{
			lotterynumbers[num] = true;
			line++; //increment for stop condition of loop
			}
		}
		
	int counter = 1;//used for indexing vector to store numbers
	
	//loop through array and when it's true then put that value 
	//into vector myLine to pass to function later
	for ( int i = 1; i <= numberofballs; i++)
		{
		if( lotterynumbers[i] )
			{
			myLine[counter] = i;
			counter++;
			}
		}
	
	 cout << endl; // new line
	
	cout << "Print vector";
	for ( int i = 1; i <= size; i++ )
		{
			cout << myLine[i] << " ";
		}
		
	cout << endl;
	
	if ( lottoWin( myLine, numberOfDraws ) )
		{
			cout << "You won after " << numberOfDraws << " tries" << endl;
		}
	else if ( numberOfDraws == 25000000 )
		{
			cout << numberOfDraws << endl;
		}

	return 0; //finish succesfully
}




//function to gen new numbers like a draw and check against line 
//generated previously
bool lottoWin ( const vector<int>& myLine, unsigned long int& numberOfDraws )
	{
		bool lotterynumbers[59]; //array to store genertated numbers
		int size = 6; // for vectors to compare
		int draw = 1; //number of balls in a line set to one and inc to <=6
		int numberOfBalls = 59;
		int num = 0;
		vector<int> lottoDraw(size);
		
		bool returnValue = false;
		
		numberOfDraws++;


		// set all elements in lottrynumbers array to false
		for ( int i = 1; i <= numberOfBalls; i++)
			{
				lotterynumbers[i] = false;
			}

		
		// 	generate 6 random numbers and set that element to true	
		while( draw <= size)
			{
				num = 1 + (rand() % 59);
				if ( !lotterynumbers[num] )
					{
						lotterynumbers[num] = true;
						draw++; //increment for stop condition of loop
					}
			}
 		
 		int counter = 1;
 	
		//loop through array and when it's true print out that element
		for ( int i = 1; i <= numberOfBalls; i++)
			{
				if( lotterynumbers[i] )
					{
						lottoDraw[counter] = i;
						counter++;
					}
			}
		
		//lottoDraw = myLine;
		
	while (( myLine != lottoDraw ))
		{
			cout << numberOfDraws << endl;
			numberOfDraws++;	
			//set all elements in lottrynumbers array to false
			for ( int i = 1; i <= numberOfBalls; i++)
				{
					lotterynumbers[i] = false;
				}

		
				//generate 6 random numbers and set that element to true	
				while( draw <= size)
					{
						num = 1 + (rand() % 59);
						if ( !lotterynumbers[num] )
							{
								lotterynumbers[num] = true;
								draw++; //increment for stop condition of loop
							}
					}
		
					int counter = 1;
	
					//loop through array and when it's true print out that element
					for ( int i = 1; i <= numberOfBalls; i++)
						{
							if( lotterynumbers[i] )
								{
									lottoDraw[counter] = i;
									counter++;
								}
						}
			
		}
	
	returnValue = true;
	
	return returnValue;
	
	}

I apologize for the quality of the code - I am very new to C++, if anyone can show me improvements that would be appreciated as well!!!!
Topic archived. No new replies allowed.