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 again!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
marz




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

Download
 Filename:  act12ex5.t
 Filesize:  1.25 KB
 Downloaded:  174 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
ShadowStorm




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




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

Smile 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! Sad
Dan




PostPosted: 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!
Blade




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




PostPosted: 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:   
   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  [ 6 Posts ]
Jump to:   


Style:  
Search: