Microsoft Small Basic

Program Listing: VZC916
' Add Game 0.1 - text version
' Copyright (c) 2013 Nonki Takahashi
'
' History:
' 02/05/2013 Created.
'
nQuestions = 20
continue = "True"
' main loop
While continue
StartTimer()
' ask 20 questions
correct = 0
For i = 1 To nQuestions
AskQuestion()
EndFor
StopTimer()
' show # of correct answer
ShowNumCorrect()
' show mesured time
ShowTime()
AskContinue()
EndWhile
Sub StartTimer
t1 = Clock.ElapsedMilliseconds
EndSub
Sub AskQuestion
a = Math.GetRandomNumber(9)
b = Math.GetRandomNumber(9)
TextWindow.Write(a + "+" + b + "=")
c = TextWindow.ReadNumber()
If a + b = c Then
correct = correct + 1
EndIf
EndSub
Sub StopTimer
t2 = Clock.ElapsedMilliseconds
EndSub
Sub ShowNumCorrect
TextWindow.WriteLine("Correct:" + correct + "/" + nQuestions)
EndSub
Sub ShowTime
TextWindow.WriteLine("Time=" + ((t2 - t1) / 1000) + "[sec]")
EndSub
Sub AskContinue
ans = ""
While ans <> "y" And ans <> "n"
TextWindow.Write("Continue? ")
ans = Text.ConvertToLowerCase(Text.GetSubText(TextWindow.Read(), 1, 1))
EndWhile
If ans = "n" Then
continue = "False"
EndIf
EndSub