keeping track
Author |
Message |
bucky-lady
|
Posted: Sat Dec 16, 2006 3:14 pm Post subject: keeping track |
|
|
hey!
so i have to add a variable to keep track of the number of tries it takes to guess the correct answer. how do i do that ? could you help me pretty please ? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
StealthArcher

|
Posted: Sat Dec 16, 2006 3:18 pm Post subject: (No subject) |
|
|
Every time you run your proc or whatever to get the users guess, and have a variable going to vlaculate something like this:
code: |
var guess,answer:string%can also be int
var tries:int:=0
proc Guess
loop
get guess
if guess =answer then
exit
else
tries:=tries+1
end if
loop
end Guess |
and run the rest from there.
Sorry if im not extremely informative. |
|
|
|
|
 |
Clayton

|
Posted: Sat Dec 16, 2006 6:56 pm Post subject: (No subject) |
|
|
Welcome to CompSci, both of you! While here, take a look see at the Turing Walkthrough to try and answer any (and most likely all) of your questions.
@StealthArcher: Your code would be better suited as a function:
code: |
fcn correct_guess (guess, answer : int) : boolean
result guess = answer
end correct_guess
loop
var guess : int
put "Please guess a number between 1 and 4"
get guess
exit when correct_guess (guess, Rand.Int (1, 4))
end loop
put "You Win!"
|
Check out the Turing Walkthrough if you have any problems understanding this. |
|
|
|
|
 |
StealthArcher

|
Posted: Sat Dec 16, 2006 9:30 pm Post subject: (No subject) |
|
|
Nope makes perfect sense to me, i just got to doing functions in class, been using turing only since the beginning of this school year, no previous programming exp of any kind so its a bit difficult to remember all the easy ways to do everything... |
|
|
|
|
 |
|
|