none
SmallBasic Random Math Help! RRS feed

  • Question

  • Hi,

    I am new to Small Basic and I am trying to make something give random math questions and you guess them. The only problem is I can't figure out how to make it when you type A it goes to Addition and when you type M it goes to Multiplication

    TextWindow.WriteLine("For Addition Type (A) for Multiplcation Type (M)")
    InputText = TextWindow.Read()
    
    Input = Controls.LastTypedTextBox
    A = Input
    M = Input
    
    If Input = A Then
      TextWindow.WriteLine("Guess the math question")
    
    M1 = Math.GetRandomNumber(10)
    M2 = Math.GetRandomNumber(10)
    
    TextWindow.WriteLine(M1 + " + " + M2 + " =")
    User = TextWindow.ReadNumber()
    
    ANS= M1+M2
    
    If M1>M2 Then
      TextWindow.WriteLine("Answer is correct!")
    Else
      TextWindow.WriteLine("Answer is incorrect. The answer was: " + ANS)
    EndIf  
    If Input = M Then
        TextWindow.WriteLine("Guess the math question")
    
    M3 = Math.GetRandomNumber(10)
    M4 = Math.GetRandomNumber(10)
    
    TextWindow.WriteLine(M3 + " * " + M4 + " =")
    User = TextWindow.ReadNumber()
    
    ANS= M3*M4
    
    If M1>M2 Then
      TextWindow.WriteLine("Answer is correct!")
    Else
      TextWindow.WriteLine("Answer is incorrect. The answer was: " + ANS)
    EndIf  
    EndIf
    Else
      TextWindow.WriteLine("Input Not Recognized")
    EndIf

    Wednesday, January 25, 2017 7:49 AM

Answers

  • Forbidden Duck,

    Here's your program that now works. I tried to do minimal changes so that you can compare this to your original program. Some enhancement suggestions.

    1. Have it check for upper and lower case A and M

    2. Have the program go back to the beginning so you don't have to restart it each time.

    TextWindow.WriteLine("For Addition Type (A) for Multiplcation Type (M)")
    InputText = TextWindow.Read()
    'Input = Controls.LastTypedTextBox
    'A = Input
    'M = Input
    If Inputtext = "A" Then
    TextWindow.WriteLine("Guess the math question")
    M1 = Math.GetRandomNumber(10)
    M2 = Math.GetRandomNumber(10)
    TextWindow.WriteLine(M1 + " + " + M2 + " =")
    User = TextWindow.ReadNumber()
    ANS= M1+M2
    If User = ANS Then
    TextWindow.WriteLine("Answer is correct!")
    Else
    TextWindow.WriteLine("Answer is incorrect. The answer was: " + ANS)
    EndIf
    elseif Inputtext = "M" Then
    TextWindow.WriteLine("Here")
    TextWindow.WriteLine("Guess the math question")
    M3 = Math.GetRandomNumber(10)
    M4 = Math.GetRandomNumber(10)
    TextWindow.WriteLine(M3 + " * " + M4 + " =")
    User = TextWindow.ReadNumber()
    ANS= M3*M4
    If User=ANS Then
    TextWindow.WriteLine("Answer is correct!")
    Else
    TextWindow.WriteLine("Answer is incorrect. The answer was: " + ANS)
    EndIf
    else
    TextWindow.WriteLine("Input Not Recognized")
    EndIf


    JR

    • Proposed as answer by litdevModerator Wednesday, January 25, 2017 6:43 PM
    • Marked as answer by Forbidden Duck Wednesday, January 25, 2017 11:01 PM
    Wednesday, January 25, 2017 4:01 PM
    Answerer