954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Lottery Program

I'm writing a Lottery program where the user type sin 4 numbers between 1 and 30, the program generates 4 random numbers. In my program I have stored the random numbers and the numbers chosen by the player in 2 separate arrays. The problem I have is that I dont know how to make the program tell the user how many numbers they have matched.

Is there an easier way than writing so many if statements, is there a way of comparing the arrays? If anyone can help me I will be very grateful.

Mus.

mus_203
Newbie Poster
11 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

A simple yet effective way to solve this would be to use a for loop to compare the elements of each array to the other using the for loop's variable. If they were equal, increment a counter variable (but don't forget to reset it after each use)

mcclth
Newbie Poster
10 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

Thanks a lot for you help I used a for loop like you said and it works fine.

Mus

mus_203
Newbie Poster
11 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You