bugged guessing game
Author |
Message |
ssr
![](http://siruisite.port5.com/ssr.jpg)
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Sat Oct 23, 2004 10:16 pm Post subject: (No subject) |
|
|
Ok...your code really is buggy.
You have a lot of redundancy in it, for example
code: |
if strintok (answer) = true then
|
You don't need the "= true" part. strintok is a boolean function, thus it returns true/false as it is...
If you're resetting 'count', just use "count := 3" instead.
And then again, why you have 'count' is a mystery, you're using a for loop thus the number of times it loops is already counted.
When an answer is guessed correctly, before the count extinguishes, one is prompted with the desicion to exit or not. This doesn't actually work...if you want to exit, it still keeps you in the main loop.
My suggestion for this is to reconsider how you've structured your programme. If you're going to use 'count' then don't bother with the for loop. It adds an extra level of unnecassary complexity to your programme that could quite simply be made without it.
|
|
|
|
|
![](images/spacer.gif) |
Hikaru79
|
Posted: Sat Oct 23, 2004 11:42 pm Post subject: (No subject) |
|
|
Here's a streamlined and WORKING version of your code. I rewrote it but tried to use as much recycled code from your program as I could. All I ask is that if you are handing this code in you CAREFULLY look it over and make sure you UNDERSTAND my code. Good luck!
code: | var answer : string
var randnum : int
var guess : int
loop
randint (randnum, 1, 10)
put "I've selected a number between 1 to 10."
put "You have three chances to guess it right! " ..
for count : 1 .. 3
get answer
if strintok (answer) then
guess := strint (answer)
else
put "Please input an integer: " ..
end if
if guess = randnum then
put "You are so lucky! It is ", randnum, "!"
elsif guess > randnum then
put "It's too big. You have ", 3 - count, " tries left!"
else
put "It's too small. You have ", 3 - count, " tries left!"
end if
end for
if guess not= randnum then
put "You have failed. The answer was ", randnum, "!"
end if
put "Do you want to give it another shot? (yes/no) " ..
get answer
if answer = "yes" or answer = "Yes" or answer = "y" or answer = "Y" then
cls
else
exit
end if
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Sun Oct 24, 2004 1:28 pm Post subject: (No subject) |
|
|
err ur code would crash if they give an invalid input
|
|
|
|
|
![](images/spacer.gif) |
|
|