So for the final part of the final project we have to edit our flowcharts and pseudocode according to the teachers comments. My flowchart was fine (thank you Kerm) but my pseudocode could use a little help. I'm not entirely sure how to fix it either, so Kerm reminded me of this helpful site. Beforehand though, I will say I don't quite understand how to write loops. Flowcharting loops, yes...Writing them, not so much. And it wasn't something that neither the teacher or the book went into that much (in detail.)

The teachers comment on my pseudocode was:
Quote:
Very good! The WHILE loop seems to be buried a little too deep in the logic. For example, in Main(), you have this IF/ELSE setup to either play again or end the game... but it will only execute once because it is not contained within any kind of loop.

All of the core pieces to this program are present and well-constructed!

While my pseudocode is as follows:
Quote:
start
Declarations
num pScore = 0
num x
string guess
string "Fox"
string "Play Again"
hints[5] = {"Computer: I am thinking of an animal that has fur. What animal is it?", "Computer: No. The animal has red fur. What is it?", "Computer: No. The animal is carnivorous. What is it?", "Computer: No. The animals young are called kits. What is it?", "Computer: No. The animal is said to have nine tails in legends. What is it?"}
animalGame()
endOfGame()
animalGame()
if "Play Again" = "Y"
animalGame()
else
endOfGame()
endif
end

animalGame()
hints[x]
input guess
if guess = "Fox" then
endif
pScore = pScore + 1
output "Computer: Correct."
return
else
x = x + 1
while x < 5
output hints[x]
input guess
endwhile
output "Computer: No. The answer was Fox."
return
endif
return

endOfGame()
output "Player's final score is ", pScore
return
As I've recommended, the absolutely best way to understand a piece of code, other than running it and stepping through it with a debugger, is to "execute" it in your mind. Try to execute the animalGame() function in your brain, pretending to be a computer and a user, and if you mentally execute it correctly, you'll very soon see where the issue is. If you don't, I strongly suggest you try again until the relationship between the ordering of the lines of code and what happens when you run it becomes clearer. This is one of those things that can only be improved with practice and effort, but I (and I believe the majority of us) find it quite fun, up to a point.

If you absolutely need a hint (and please make some effort to solve it yourself first), please follow your professor's suggestion to focus on the following loop:
Code:
```while x < 5 output hints[x] input guess endwhile ```

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum