Lotto Program *

Please Give Me Where to Start..
i Plan to make a program that goes like this...

"Enter Your Name:

then after you input your name

*Enter 6 number from 1 -49: ( because lotto is 6/49)

after you input.. it will randomly output 6 number from 1-49...

if the numbers that you have inputted have similarity from the random output it will go like this...

ex.
"You have Matched 3 numbers! "Enter YOur name" have won 30,000 dollars!

and after that.. the program will ask you if you want to go again...

please help.. i dont know how to start...
Last edited on
In words (always a great place to start), a simple (not necessarily the most efficient) procedure might go something like this:
1. Get the name from the user, store it
2. Get the six numbers from the user, store them in an array
3. Populate another array with six random numbers between 6 and 49.
4. For each of the randomly-generated numbers, see if the user guessed that number. If yes, increment the 'number matched' count by one.
5. Based on the number of matches, award prizes as appropriate...

Step 4 should inspire you to use a 'for' loop. Step 5 should inspire you to use a 'switch' statement or an 'if-else' control structure...

You know at compile time that you'll always be dealing with sets of six numbers, so you can statically declare an array to hold the numbers that the user inputs:

int userEntries[6];

Similarly, declare another array to hold the randomly-generated numbers.

You can then populate the user and random arrays by using cin and a random-number-generating function respectively. See http://www.cplusplus.com/reference/clibrary/cstdlib/rand/

Hope this gets you started. Post your code if you get stuck.

Note: I guess this lotto is drawn WITHOUT replacement, right? That means that you can't have the same number drawn twice. Think about what that means for your program...

Further interesting note: The 'random' functions found in programming libraries are not truly 'random'. They are 'pseudo-random'. Check out http://www.random.org/ for an interesting discussion on the topic :).
thx sammy.. that should get me started.. :) thx thx.. ill tell you if i have any problems..
ok.. i tried but i got clueless how to use " int userEntries[6]"
how would i put it in together with my program and how do i input the 6 numbers?
So when the compiler sees 'int userEntries[6]', it allocates memory for six integers. You can access one of those integers using 'userEntries[0]' for the first element, 'userEntries[5]' for the sixth element etc.

ex. You can store an integer to the first element in this collection like this:

userEntries[0] = 25

ex. You can read an integer from the fifth element in this collection like this:

int myInt = userEntries[4]

A very basic way to input the numbers (note that there is no validation here) could be:
1
2
3
4
5
cout << "Enter 6 numbers, one on each line...";
for(int i=0; i<6; i++)
{
	cin >> userEntries[i];
}




how can i compare 2 arrays .. and output the similiraties of the inputed array and the random array?
I guess that depends on how you want to do the comparison. Do you only want to compare the same element number in both arrays (i.e. if inputArray[0] == randomArray[0], for example), or do you want to compare each element with every other element in the other array?

The former is an easy case, and would simply be a 'for' loop iterating over the common size of both collections, with your comparison logic inside the for loop. The latter would in the simplest case involve a NESTED 'for' loop, where each element of the second array is compared to each element in the first.

That is...

1
2
3
4
5
for each element x[i] in collection x
   for each element y[j] in collection y
      do something with x[i] and y[j], like check if they're equal and increment a counter
   end iteration for y[j]
end iteration for x[i] 

can you do an example for me?
WOOOH! finished it complete with comparing and prizes.. thx for the help sammy its much appreciated.. :D I've done the program from 7pm-2am
Hehe get excited! Nice work :). Glad to be of help...
Topic archived. No new replies allowed.