Guess the number: Difference between revisions

(Add Quackery)
Line 522:
<lang qbasic>
' OPTION EXPLICIT ' Remove remark for VB-DOS/PDS 7.1
'dIM
 
' Var
DIM n AS INTEGER, g AS INTEGER, t AS INTEGER, a AS STRING
Line 571:
END FUNCTION
</lang>
 
==={{header|QB64}}===
The following is a modification of the above polished version in QBasic with explanations of differences.
<lang QB64>Randomize Timer 'Moved to the head as it is an initialization statement,
'although it could be placed anywhere prior to the Rnd() function being called.
 
'Dimensioning the function is not required, nor used, by the QB64 compiler.
 
'Var
Dim As Integer n, g, t 'Multiple variables of the same type may be defined as a list
Dim As String a 'Variables of different types require their own statements
Const c = 10
 
' Program to guess a number between 1 and 10
Do
Cls
Print "Program to guess a number between 1 and 10"
n = Int(Rnd * c) + 1 'Removed the function call since this was the only statement left in it
t = 0
Do
t = t + 1
Do
Print "Type a number (between 1 and " + LTrim$(Str$(c)) + "): "; 'FORMAT$ is not a function in QB64
'The Str$() function converts the number to its text
'value equivalent, while LTrim$() removes a leading
'space character placed in front of positive values.
Input "", g
If g < 1 Or g > c Then Beep
Loop Until g > 0 And g < (c + 1)
 
' Compares the number
Select Case g
Case Is > n: Print "Try a lower number..."
Case Is < n: Print "Try a higher number..."
Case Else: Print "You got it! Attempts: " + LTrim$(Str$(t)) 'Use of LTrim$() and Str$() for the same reason as above
End Select
Loop Until n = g
Print
Print "Do you want to try again? (Y/n)"
Do
a = UCase$(InKey$)
If a <> "" And a <> "Y" And a <> "N" Then Beep
Loop Until a = "Y" Or a = "N"
Loop Until a = "N"
Print
Print "End of the program. Thanks for playing."
End</lang>
 
==={{header|ZX Spectrum Basic}}===