Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 help with numbers game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
marz




PostPosted: Mon May 05, 2003 4:44 pm   Post subject: help with numbers game

Hi. I'm supposed to make a numbers game where it tells you the number of guesses you took to get the correct number. Now, here is what i have so far:
var number, guess : int
var number_of_guess : int :=1
colour(9)
randomize
randint (number, 1, 100)
loop
put "Enter a guess between 1 and 100: " ..
get guess
if guess = number then
colour(6)
put "WOW! You're right! good job"
if number_of_guess = 1 then
colour(4)
put "YAAAAA!!!!!!!! You got it in ", number_of_guess, " try!!"
elsif number_of_guess > 1 then
colour(17)
put "It took you ", number_of_guess, " tries to get this. Do better next time!"
end if
put "The number was ", number
end if
if guess > number then
colour(11)
put "Sorry! You're guess is too HIGH!!"
sound(100,100)
elsif guess < number then
colour(12)
put "Sorry! You're guess is too LOW!"
sound(1000,100)
end if
number_of_guess := number_of_guess + 1
exit when guess = number
end loop

ok, so now i have to modify the program so that the number of guesses taken so far is displayed on the screen.
Then i need to modify the program furthur by allowing the user to give up by entering a guess of -1. If the user gives up, then the number of guesses taken so far along with teh "hidden" number are to be displayed on the screen. Now, i dont understand a word of this... so if anyone could help me with the codes, it would be greatly appriciated! Very Happy Thanx SO MUCH!
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon May 05, 2003 4:54 pm   Post subject: (No subject)

first - plz use [code] and [/code] tags around your code. Easier to read.

Now, to count guesses, you just declear an int variable and initialize it to 0. Each time user takes a guess, you add +1 to it, so at the end you can just use "put counter" and it will tell you how many times you guessed.
(looking at your code I think you already have it done)

You know how you use a loop to keep on taking guesses? And "exit when" to exit when the guess is right? Just add another exit when guess = -1.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nate




PostPosted: Mon May 05, 2003 6:48 pm   Post subject: Marz

What skewl you go 2?


-Nate
marz




PostPosted: Wed May 07, 2003 8:15 am   Post subject: (No subject)

Yeah, what school do you go to? I go to school somewhere in Canada.
But, with the program, i only have it so far as to tell the number of guesses that you have taken altogether. I still dont know how to make it so that when they guess a number, it tells them, "you have guessed one". Please help!
Tony




PostPosted: Wed May 07, 2003 9:17 am   Post subject: (No subject)

... you have it in your program already...

code:

if guess = number then
colour(6)
put "WOW! You're right! good job"


or do you mean display what number user has guessed? then its
code:

put "you have guessed ", guess
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: