Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
help with numbers game
Author Message
marz

Posted: 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! Thanx SO MUCH!

Tony

Posted: 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.

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.
Tony's programming blog. DWITE - a programming contest.
nate

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

What skewl you go 2?

-Nate
marz

Posted: 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

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

 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
Tony's programming blog. DWITE - a programming contest.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 5 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: