
-----------------------------------
applejack
Tue Dec 14, 2004 3:57 pm

Please Help with &quot;Guess the Word&quot; game!!!
-----------------------------------
Please, I am a noob Turing student and i have to finish this "guess the word" game :(

So far i think it is correct, but, my problem is when you type in a letter it doesnt carry over to the next turn. 

like if the word is APPLE,  i type A, the thing will say A****. this is fine BUT

next turn i type P, the thing will say *PP**. it forgets that i typed A the first time. Please help!  :cry:

-----------------------------------
Cervantes
Tue Dec 14, 2004 7:10 pm


-----------------------------------

strWordForPuzzle := randomWord ()
intLengthOfPuzzle := length (strWordForPuzzle)
var strToOutput : array 1 .. intLengthOfPuzzle of string
for i : 1 .. upper (strToOutput)
    strToOutput (i) := "*"
end for

loop

    put "what is your guess? " ..
    get guess

    for i : 1 .. intLengthOfPuzzle
        if (guess = strWordForPuzzle (i)) then
            strToOutput (i) := guess
        end if
    end for

    put "TESTING AGAIN: ", strFoundLetters

    for k : 1 .. intLengthOfPuzzle
        put strToOutput (k) ..
    end for
    put ""

end loop


-----------------------------------
applejack
Tue Dec 14, 2004 7:46 pm


-----------------------------------
Thanks!......but could you show me somthing without using Arrays?
Im kind of looking for a code with a loop inside a loop.

-----------------------------------
Cervantes
Tue Dec 14, 2004 7:58 pm


-----------------------------------
Why must it have a loop within a loop?  Is that what the assignment sheet says?

-----------------------------------
applejack
Tue Dec 14, 2004 8:01 pm


-----------------------------------
Hey! b/c we didnt really learn arrays yet, so I am stuck learning with for loops. Cuz if i use arrays he will think something is fishy lol :(

so far we have learned up to functions.

-----------------------------------
Cervantes
Tue Dec 14, 2004 8:21 pm


-----------------------------------
So, as long as your teacher doesn't suspect anything fishy, life's good?

This time, no direct code.
There are probably several ways of doing this, without using arrays.  I will detail the way I approached the problem.
I created two string variables that I could manipulate.  Only one of them would actually be drawn to the screen (ie. "").  Using a for loop, determine if the guess is contained within the word in question.  If it is, add that character to the to_be_outputted string (using +=).  If not, add the character from the temporary string (to other string) that corresponds with the character of the word in question.  That is, make use of your for loop here.
When that for loop is done, output the to_be_outputted string, and return to the beginning of the main loop.  
You should also use exit to exit the loop when all the letters in the word have been guessed.

-----------------------------------
applejack
Tue Dec 14, 2004 8:34 pm


-----------------------------------
oh ok... umm

now i have this...


var intMatch:int
intMatch := 0

intlengthfound := length(strfound)
for i:1..intLengthOfPuzzle
      for j:1..intlengthfound
           if (strGame  = strfound(j)) then
           
           intMatch := 1
           
           put strGame ..
           else
                put "*"..
                
           end if
      end for
end for

put ""

intMatch := 0
end loop

-----------------------------------
Cervantes
Tue Dec 14, 2004 8:53 pm


-----------------------------------
:? What are these variables?  :think:
I quite clearly told you the code that you need.  Really, the only thing that I left open ended was how to determine if the guess is contained within the word in question.  
You're still outputting all *'s except the current guess, if it was correct.  You have to store the string of * and correct letters in a string.
Keep working :)

P.S. Use [ code][ /code] tags, please.  :wink:

-----------------------------------
applejack
Tue Dec 14, 2004 8:58 pm


-----------------------------------
gahh lol its hard....i am trying but the due time is 10:30 pm today! im rushing lol  thanks for your help so far tho man! appreciate it:D

-----------------------------------
applejack
Tue Dec 14, 2004 9:43 pm


-----------------------------------
gah...its too hard for my skill......im dead. lol thanks for trying to help! :D
