944,164 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4085
  • Java RSS
Nov 28th, 2004
0

Lottery Program

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mus_203 is offline Offline
11 posts
since Sep 2004
Nov 28th, 2004
0

Re: Lottery Program

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)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mcclth is offline Offline
10 posts
since Nov 2004
Dec 1st, 2004
0

Re: Lottery Program

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

Mus
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mus_203 is offline Offline
11 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Syntax Analyser and General Java Help
Next Thread in Java Forum Timeline: Text Searching





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC