Guess It in FreeBASIC
' Guess what number for FreeBASIC .17b stable
' E.K.virtanen. 2007, public domain

Randomize TIMER
CONST MIN = 1
CONST MAX = 100
Dim AS Integer Plr_guess, Randomed, Rounds

' Main module of program.
DO
    Color 15, 0 : CLS
    Randomed = INT(RND * ((MAX + 1) - MIN) + MIN)
    Rounds = 0
    Print "Ok, i think random number between "; MIN; MAX; "."
    Print "Your job is to guess what it is in as minimal tries as possible."
    Print ""
    Print "After your every guess, ill give you hint is my number higher or lower than your guess."
    Print "You can exit by 'guessing' 0."
    Print "Press any key to start game."; : GETKEY

    ' From here starts the gaming loop itself. This is looped until guess it right one.
    CLS
    DO
        Rounds = (Rounds + 1)
        Print "This is round number: "; Rounds; "."
        INPUT "Give your guess: "; Plr_guess

        Color 14, 0
        IF Plr_guess > Randomed THEN
            Print "My number is smaller..."
        END IF

        IF Plr_guess < Randomed THEN
            Print "My number is higher..."
        END IF
        Color 15, 0
        IF Plr_guess = Randomed THEN EXIT DO

    LOOP While Plr_Guess <> 0

    IF Randomed <> Plr_Guess THEN EXIT DO

    Print "You got it!!!"
    Print "It took "; Rounds; " rounds to guess right number."
    Print ""
    Print "Press 'y' to play again. Any other key to quit."
    DO Until INKEY$ <> "" : Loop
    IF INKEY$ <> "y" AND INKEY$ <> "Y" THEN EXIT DO
Loop
END
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.