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

Posted: Mon Jun 02, 2003 7:49 pm   Post subject: help with numbers game again!

Alright, For this number game that we are doing, we must make the game exit when the user takes 10 guesses. I dont know how to do this, or what codes to use. Here is my programming so far.

act12ex5.t
Description:
Filename:  act12ex5.t
Filesize:  1.25 KB

Posted: Mon Jun 02, 2003 9:11 pm   Post subject: (No subject)

Here's the source code of a program i made a while back.. hope this helps...

 code: const SECRET_NUMBER := Rand.Int(1,100) var counter : int := 0 var userGuess : int loop put "Guess a number from 1 to 100 " get userGuess if userGuess > SECRET_NUMBER then put "YOUR GUESS IS TOO HIGH!" put skip elsif userGuess < SECRET_NUMBER then put "YOUR GUESS IS TOO LOW!" put skip end if counter := counter + 1 exit when counter >= 10 exit when userGuess = SECRET_NUMBER end loop if userGuess = SECRET_NUMBER then put "YOU WIN!!" elsif counter >= 10 then put "YOU LOSE!!" end if
marz

Posted: Mon Jun 02, 2003 10:23 pm   Post subject: (No subject)

Thanks for the code. It gave me a new perspective on how to do the numbers game. However, i still need to know how to make the game exit when the user has taken 10 guesses. Also, it has to say instead of "you have taken one guess so far", it has to say "you only have 9 guesses left." PLEASE HELP!
Dan

Posted: Tue Jun 03, 2003 12:03 am   Post subject: (No subject)

ah, i think his code dose that and i whould hop you know how to chage/add the put stamtes you need.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!

Posted: Tue Jun 03, 2003 11:18 am   Post subject: (No subject)

theres two ways you can do this: first of all you make a variable that contains the amount of guesses and in your case you would set it to ten. in the if statement where you check to see if the's guessed the answer. if its wrong. subtract one from the total giving him 9. use this variable in your put statement to tell them how many you have left. also. in your loop have exit when chances = 0
 code: var chances:int:=10 loop put "You have ",chances," left" %your if statement checking to see if he has the right answer %if not subtract one from chances exit when chances = 0 end loop

the other way is to run a decreasing for loop from 10 and also have a condition to exit when he gets the right answer
 code: for decreasing i:10..0 put "you have ",i," chances left" %exit when dude has the right answer end for
Andy

Posted: Tue Jun 03, 2003 2:11 pm   Post subject: (No subject)

ha, i made that program on the ti 83 plus calculator
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 6 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: