Hi All,
This is a final clarification. Please read it very carefully before you
ask any questions, you are all confusing human_guess() and
computer_guess(). I will cover the special/error cases mentioned on the
newsgroup so far about both functions, there possibly can be other cases I
am not aware of:
human_guess():
**************
1) The case you need to take care of is if the HUMAN USER guesses a number
that is less than 1 or more than 100.
Example:
- Human guesses -156666 -> Computer replies "Too low" and continues the
game normally (Do not terminate).
- Human guesses 435435435 -> Computer replies "Too High" and continues the
game normally (Do not terminate).
So far so good? This has been clarified earlier by Alexander Smith.
computer_guess():
*****************
1) This is the case I am referring to.
Lets say I am the human player and pick a number 167 (which is out of
range) and I want the computer to guess this number, but the computer does
not know YET that its out of range. The computer starts guessing:
- Computer guesses 34 -> You reply "l" for TOO LOW
- Computer then guesses 76 -> You reply "l" for TOO LOW
- Computer then guesses 97 -> You reply "l" for TOO LOW
- Computer then guesses 99 -> You reply "l" for TOO LOW
- Computer then guesses 100 -> You still reply "l" for TOO LOW
Obviously, this is an irrecoverable error situation. In this case, your
code should print an error message starting with "error:" and terminate
using exit(1);
2) You (HUMAN USER) dont have any number in mind. The computer starts
guessing as follows:
- Computer guesses 50 -> You decide to hit "l" for TOO LOW (You randomly
selected "l" and not "h")
- Computer then guesses 100 -> You decide to hit "h" for TOO HIGH (You
randomly selected "h" and not "l"). Notice that here lies difference
between this case and case 1.
- Computer then guesses 52 -> You decide to hit "h" for TOO HIGH (You
randomly selected "H" and not "l").
- Computer then has no other choice but to output 51 as your guess,
although you did not really have a number in mind, you were just pressing
randomly "l" and "h".
In this case (case 2), you dont need to take care of anything. Your code
should automatically print 51 out as mentioned by Alexander earlier.
3) You (HUMAN USER) dont have any number in mind. The computer starts
guessing as follows:
- Computer guesses 50 -> You decide to hit "l" for TOO LOW (You randomly
selected "l" and not "h")
- Computer guesses 95 -> You decide to hit "h" for TOO HIGH (Random)
- Computer guesses 51 -> You decide to hit "h" for TOO HIGH (random). Note
that here lies the difference between this case 3 and the previous case 2.
Here the computer doesnt have any one choice left, its "stuck" between 50
and 51.
You dont need to do anything special either, if your code runs
correctly, the computer will keep asking you about number 51 until you
eventually press "CORRECT".
This case 3 has been explained earlier in one of your colleagues emails
which is possible.
============================
The above is a combined summary of the cases that have been discussed on
the newsgroup before, nothing has been altered and nothing is
contradictory.
Again, I want to stress that we're all trying to help you, there is no
need to panic :) Ideally though you shouldnt be told about error handling
because its essential.
I hope this post clarifies many issues.
If you continue to have problems with regards to this specific topic
(guess.c special cases), you can email me directly and I will clarify
things. But please read this post many times to avoid confusing others.
Good luck!