Wednesday, October 12, 2011

Multiplication Practice Game 1.0

This little QBasic program generates a random, single-digit multiplication problem. If you enter the correct product, you will earn accumulative points equal to the sum of the multiplicand and the multiplier, as well as be presented with a new problem. If you fail to solve a problem correctly, you will be given the correct product and receive a message based on your final score.

RANDOMIZE TIMER

iScore% = 0

DO

        CLS
        iNum1% = RND * 9
        iNum2% = RND * 9
        iContinue% = 0

        PRINT iNum1%; "x"; iNum2%
        INPUT "", iResult%

        IF iResult% = iNum1% * iNum2% THEN
                PRINT "Correct!"
                iContinue% = 1
                iScore% = iScore% + iNum1% + iNum2%
                PRINT "SCORE:"; iScore%
        ELSE
                PRINT "Sorry! The correct answer was"; iNum1% * iNum2%
                iContinue% = 0
                SLEEP 4
        END IF

        SLEEP 1

LOOP WHILE iContinue% = 1

CLS
PRINT "Your score was"; iScore%

SELECT CASE iScore%
        CASE 0 TO 10
                PRINT "You Need To Try Harder!"
        CASE 11 TO 20
                PRINT "You Can Do Better!"
        CASE 21 TO 30
                PRINT "Not Bad!"
        CASE 31 TO 40
                PRINT "You Did Good!"
        CASE 41 TO 50
                PRINT "You Did VERY Good!"
        CASE 51 TO 60
                PRINT "Impressive!"
        CASE 61 TO 70
                PRINT "Awesome Job!"
        CASE 71 TO 80
                PRINT "Amazing Work!"
        CASE 81 TO 90
                PRINT "Absolutely Fantastic!"
        CASE IS > 90
                PRINT "Multiplication Excellence Re-Defined!"
                PRINT "Tell Your Parents That You Are Ready For The Next Level!"
END SELECT

END


Since most of you wont have access to QBasic, I converted it to a Visual Studio 2010 Console Program for you.


Module Module1

    Sub Main()
        Randomize(Timer)

        Dim iScore As Long = 0

        Dim iNum1 As Integer
        Dim iNum2 As Integer
        Dim iContinue As Integer
        Dim iResult As Integer

        Do

            Console.Clear()

            iNum1% = Rnd() * 9
            iNum2% = Rnd() * 9
            iContinue% = 0

            Console.WriteLine("Solve: " & iNum1 & " x " & iNum2 & " = ")
            iResult = Console.ReadLine

            If iResult% = iNum1% * iNum2% Then
                Console.WriteLine("Correct!")
                iContinue = 1
                iScore += iNum1 + iNum2
                Console.WriteLine("SCORE:" & iScore)
            Else
                Console.WriteLine("Sorry! The correct answer was " & iNum1 * iNum2)
                iContinue = 0
                System.Threading.Thread.Sleep(3000)
            End If

            System.Threading.Thread.Sleep(1000)

        Loop While iContinue% = 1

        Console.Clear()

        Console.WriteLine("Your score was " & iScore)

        Select Case iScore
            Case 0 To 10
                Console.WriteLine("You Need To Try Harder!")
            Case 11 To 20
                Console.WriteLine("You Can Do Better!")
            Case 21 To 30
                Console.WriteLine("Not Bad!")
            Case 31 To 40
                Console.WriteLine("You Did Good!")
            Case 41 To 50
                Console.WriteLine("You Did VERY Good!")
            Case 51 To 60
                Console.WriteLine("Impressive!")
            Case 61 To 70
                Console.WriteLine("Awesome Job!")
            Case 71 To 80
                Console.WriteLine("Amazing Work!")
            Case 81 To 90
                Console.WriteLine("Absolutely Fantastic!")
            Case Is > 90
                Console.WriteLine("Multiplication Excellence Re-Defined!")
                Console.WriteLine("Tell Your Parents That You Are Ready For The Next Level!")
        End Select

        System.Threading.Thread.Sleep(5000)

        End

    End Sub

End Module

No comments:

Post a Comment