Lottery Program

Reply

Join Date: Sep 2004
Posts: 11
Reputation: mus_203 is an unknown quantity at this point 
Solved Threads: 0
mus_203 mus_203 is offline Offline
Newbie Poster

Lottery Program

 
0
  #1
Nov 28th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 10
Reputation: mcclth is an unknown quantity at this point 
Solved Threads: 0
mcclth mcclth is offline Offline
Newbie Poster

Re: Lottery Program

 
0
  #2
Nov 28th, 2004
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)
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 11
Reputation: mus_203 is an unknown quantity at this point 
Solved Threads: 0
mus_203 mus_203 is offline Offline
Newbie Poster

Re: Lottery Program

 
0
  #3
Dec 1st, 2004
Thanks a lot for you help I used a for loop like you said and it works fine.

Mus
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC