Making a Visual Studio program for random arithmetic questions

Tags:
Visual Studio 2010
Hey, I am currently trying to make a program that asks 10 random arithmetic questions before giving them a score out of 10. I am wondering how would I randomize the subtraction, addition, division and multiplication questions to randomly be selected?


Software/Hardware used:
Visual studio 2010
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 6  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    Show us what you have so far. Sounds like homework. We can point you in the right direction.
    131,380 pointsBadges:
    report
  • Hihowareyou
    Module Module1

        Sub Main()
            Randomize()
            Dim RandomNum As New Random

            Dim correctAnswer As Single
            Dim Number1 As Integer
            Dim Number2 As Integer
            Dim Operation As Integer
            Dim Output As String
            Dim Answer As String


            Number1 = RandomNum.Next(1, 10)
            Number2 = RandomNum.Next(1, 10)
            Operation = RandomNum.Next(1, 4)


            If (Operation = 1) Then
                Output = " + "
                correctAnswer = Number1 + Number2
            ElseIf (Operation = 2) Then
                Output = " - "
                correctAnswer = Number1 - Number2
            ElseIf (Operation = 3) Then
                Output = " * "
                correctAnswer = Number1 * Number2
            Else
                Output = " / "
                correctAnswer = Number1 / Number2
            End If


            Console.WriteLine("What is " & Number1 & Output & Number2 & "?")
            Answer = Console.ReadLine()

            Console.WriteLine("Your answer is " & Answer)
            Console.WriteLine("The correct answer is " & correctAnswer)

            Console.ReadLine()

        End Sub

    End Module

    This is what I have so far, my mind is blank on how to repeat the question 10 times, as well as after the ten questions displaying a final answer. Thanks for your help!
    35 pointsBadges:
    report
  • ToddN2000
    Try wrapping your code in a DO loop. Start just before the initialization of your randomization and END just before the END SUB. Then test using debug... If you still have a problem, report back.
    131,380 pointsBadges:
    report
  • Hihowareyou
    The Two numbers never change, once the loop starts the numbers do no longer randomize, any ideas?
    35 pointsBadges:
    report
  • ToddN2000
    Hint:
    Does the operation change?
    Are these NEW instances of of your fields?
    131,380 pointsBadges:
    report
  • Hihowareyou
    Ahh thank you. I figured it out. I'll check back if I don't manage to tell the loop to loop for 10 times :)
    35 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: