Question Lottery Results Checker

watsee

New member
Joined
May 11, 2010
Messages
1
Programming Experience
Beginner
Hi all

I'm a newbie to VB and such, I'm currently working on a program that allows users to play the National Lottery. The program generates random numbers for a lucky dip, allows users to log in etc. The problem I'm having is the feature that allows users to input their own results and check them against the 'current results' (just a randomised list of numbers) and work out what prizes if any the user is entitled to.

Now obviously there are many different combinations of which numbers are the same. My question is:

Is there any way (short of writing an IF statement catering for each combination possible) I could check these results? Perhaps with the use of a loop? I don't know I'm very new to this.

Any help would be greatly appreciated.
 
VB.NET:
Dim picks() As Integer = {1, 2, 3}
Dim results() As Integer = {1, 3, 5, 7, 9}
Dim wins As Integer
for example
VB.NET:
wins = (From x In picks Where results.Contains(x)).Count
or
VB.NET:
wins = picks.Count(Function(x) results.Contains(x))
 
Hey dude, there is probably a much easier, or more efficient way of checking this, however I have made a small function that will cater your needs (for now).

VB.NET:
    Public Function check(ByVal picks As Integer(), ByVal results As Integer()) As String
        Dim numbersMatch As Integer = 0
        For i As Integer = 0 To picks.Count - 1
            For j As Integer = 0 To results.Count - 1
                If picks(i) = results(j) Then
                    numbersMatch += 1
                End If

            Next
        Next

        Select Case numbersMatch
            Case 6
                Return "JACKPOT!!!"
            Case Is <= 3
                Return "Sorry, only " + numbersMatch + " numbers matched"
            Case Is >= 4 <= 6
                Return "Winner!"
        End Select

        Return Nothing
    End Function

If you need me to explain how it works then I will
 
Back
Top