Please Help with "Guess the Word" game!!!
Author |
Message |
applejack
|
|
|
|
|
Sponsor Sponsor
|
|
|
Cervantes
|
Posted: 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
|
Posted: 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
|
Posted: 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
|
Posted: 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
so far we have learned up to functions.
|
|
|
|
|
|
Cervantes
|
Posted: 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
|
Posted: 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
|
Posted: Tue Dec 14, 2004 8:53 pm Post subject: (No subject) |
|
|
What are these variables?
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.
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
applejack
|
Posted: 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
|
Posted: 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!
|
|
|
|
|
|
|
|