
-----------------------------------
DaveAngus
Tue Mar 18, 2008 8:25 am

Simple Guessing game
-----------------------------------
This is a great assignment for teaching the basics of randint s



******Assignment******

Create a game that will process a random integer and then when the user guesses,
output if they are too high, too low or right on.
Also, calculate the number of guesses it takes for the user to guess the answer.



/*
 Name : Dave Angus
 Date : March 17th 2008
 Task : Random number
 */

var num1 : int
var counter : int
var guess : int
var lvl : int
counter := 0

/*
 Level selection.
 Determins what the randint will be between
 */

put "Hello and welcome to the number guessing game!"
put "Please select a level to play (1-4)"
put "Level 1 = 1-25"
put "Level 2 = 1-50"
put "Level 3 = 1-75"
put "Level 4 = 1-100"
get lvl

if lvl = 1
        then
    randint (num1, 1, 25)
elsif lvl = 2
        then
    randint (num1, 1, 50)
elsif lvl = 3
        then
    randint (num1, 1, 75)
elsif lvl = 4
        then
    randint (num1, 1, 100)

end if

/* This loop is where people make the guess.
 I have set a delay so that people can read if they are too high or too low.
 I wanted to clear screen so that it looks cleaner*/

loop
    cls
    put " Please make your first guess: "
    get guess


    if num1 > guess then
        put "You are too low. Try again!"
    elsif num1 < guess then
        put "You are too high. Keep going!"
    elsif num1 = guess then
        put "You are correct!!!"
        exit
    end if
    counter := counter + 1
    delay (2000)
end loop

/* This determines how long it took for the user to guess the number.
 I have also added comments depending on their score.
 */

put "It took you " ..
put counter ..
put " guesses to correctly guess the number!"

if counter = 1 then
    put "You should buy a lottery ticket!"
elsif counter 