Computer Science Canada

Guessing game

Author:  MidnightDragon [ Wed Nov 22, 2006 2:50 pm ]
Post subject:  Guessing game

I was wondering if some1 could help me fix up my code for this guessing game

code:
%The Guessing Game
%Choose a number at random between 1 and 20
%And allows you to guess it.
var hidden, guess :int
var reply : string
var count : int :=0
var tries: int:=0
randint (hidden,1,20)
put "Do you want to play the game? y or n"
loop
get reply
exit when reply = "n"
if reply = "y" then
put "Enter Your Guess between 1, 10 "
get guess

tries:=tries+1
if tries > 5 then

put "Too many tries, You loose"
exit
end if

if guess=hidden then
put "You Won"
elsif guess>hidden then
put "Too High do you want to try again enter y or n"
elsif guess<hidden then
put "Too Low do you want to try again enter y or n"
end if
end if
end loop


I need to fix the part that after you take ur first guess and it's wrong it reaskes if u want to play but i need to take that out and also at the end it asks if you want to play again i need it to restart but i can't figure that one out either. If theres more info that you need just ask thanks

Author:  MidnightDragon [ Wed Nov 22, 2006 2:54 pm ]
Post subject: 

This is the revised code i just relized that i had the do you want to play again in the put statment

code:
%The Guessing Game
%Choose a number at random between 1 and 99
%And allows you to guess it.
var hidden, guess :int
var reply : string
var count : int :=0
var tries: int:=0
randint (hidden,1,10)
put "Do you want to play the game? y or n"
loop
get reply
exit when reply = "n"
if reply = "y" then
put "Enter Your Guess between 1, 10 "
get guess

tries:=tries+1
if tries > 5 then

put "Too many tries, You loose"
exit
end if

if guess=hidden then
put "You Won"
elsif guess>hidden then
put "Too High"
elsif guess<hidden then
put "Too Low"
end if
end if
end loop


But now that thats fixed it stops completly


: