Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Please Help with "Guess the Word" game!!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
applejack




PostPosted: Tue Dec 14, 2004 3:57 pm   Post subject: Please Help with "Guess the Word" game!!!

Please, I am a noob Turing student and i have to finish this "guess the word" game Sad

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! Crying or Very sad



WHAT IS THE WORD GAMEI.T
 Description:

Download
 Filename:  WHAT IS THE WORD GAMEI.T
 Filesize:  2.16 KB
 Downloaded:  335 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Dec 14, 2004 7:10 pm   Post subject: (No subject)

Arrays are helpful for a program like this.

code:

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




PostPosted: Tue Dec 14, 2004 7:46 pm   Post subject: (No subject)

Thanks!......but could you show me somthing without using Arrays?
Im kind of looking for a code with a loop inside a loop.
Cervantes




PostPosted: Tue Dec 14, 2004 7:58 pm   Post subject: (No subject)

Why must it have a loop within a loop? Is that what the assignment sheet says?
applejack




PostPosted: Tue Dec 14, 2004 8:01 pm   Post subject: (No subject)

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 Sad

so far we have learned up to functions.
Cervantes




PostPosted: Tue Dec 14, 2004 8:21 pm   Post subject: (No subject)

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. []bput[/b] on to the screen). The other was just a temporary holder.
I set them both to be fully comprised of stars (*) and have the same number of characters as the word that is being guessed at.
So, if the word is pizza, both strings would = "*****".
Then, inside the main loop, get the user's guess. Make the temporary string equal the to_be_outputted string, then make the to_be_outputted string = to nothing (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




PostPosted: Tue Dec 14, 2004 8:34 pm   Post subject: (No subject)

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




PostPosted: Tue Dec 14, 2004 8:53 pm   Post subject: (No subject)

Confused What are these variables? Thinking
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 Smile

P.S. Use [ code][ /code] tags, please. Wink
Sponsor
Sponsor
Sponsor
sponsor
applejack




PostPosted: Tue Dec 14, 2004 8:58 pm   Post subject: (No subject)

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




PostPosted: Tue Dec 14, 2004 9:43 pm   Post subject: (No subject)

gah...its too hard for my skill......im dead. lol thanks for trying to help! Very Happy
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  [ 10 Posts ]
Jump to:   


Style:  
Search: