Discussion:
guess.c Special Case
(too old to reply)
Moayad Fahim Ali
2004-01-24 07:25:18 UTC
Permalink
This is regarding the function computer_guess() in guess.c.

Please take into consideration the special cases when the number guessed
is greater than 100 or less than 1. Your code should generate an error
message of the form "error: ... something here ..." informing the user
that the number is impossible. The program should also terminate.
Belov Mihhail
2004-01-24 19:14:37 UTC
Permalink
Why are we being told this the day before the program is due?

I'm sure most people have already written the program. In my case I have
the computer asking the user for the correct input in a loop so as to
ensure number between 1 and 100 are entered.
If you want us to do some "specific" procedure during a special case you
should indicate it in the lab handout.

The reason I think it is a big deal is because a computer program is
marking our programs, which is inflexible to the style of programming we
use.


-Mike
Post by Moayad Fahim Ali
This is regarding the function computer_guess() in guess.c.
Please take into consideration the special cases when the number guessed
is greater than 100 or less than 1. Your code should generate an error
message of the form "error: ... something here ..." informing the user
that the number is impossible. The program should also terminate.
Hammad Imad
2004-01-24 19:47:35 UTC
Permalink
On Sat, 24 Jan 2004, it was written:


I completely agree,this wasnt at all described in the lab handout.Ive
already finished my program, now i have to start again from scratch.I cant
see how this is any of our problems. the lab handout never said we had to
do it,seriously the handout for lab2 is almost out and now they're
changing lab1!!!
Post by Belov Mihhail
Why are we being told this the day before the program is due?
I'm sure most people have already written the program. In my case I have
the computer asking the user for the correct input in a loop so as to
ensure number between 1 and 100 are entered.
If you want us to do some "specific" procedure during a special case you
should indicate it in the lab handout.
The reason I think it is a big deal is because a computer program is
marking our programs, which is inflexible to the style of programming we
use.
-Mike
Post by Moayad Fahim Ali
This is regarding the function computer_guess() in guess.c.
Please take into consideration the special cases when the number guessed
is greater than 100 or less than 1. Your code should generate an error
message of the form "error: ... something here ..." informing the user
that the number is impossible. The program should also terminate.
Moayad Fahim Ali
2004-01-24 19:57:24 UTC
Permalink
Hi Mike,

Whenever the user is supposed to enter input to the program, the input
should be validated for correctness. In human_guess(), the human can not
input a number that is out of bound, that should be treated as an error.
Similarly, in computer_guess(), it is an error for the human user to tell
the computer that its guess is higher than 100 or lower than 1 and should
be treated as such.

Please note:

1. The "special" procedure I clarified was posted on the class website
under the Error Handling section of the "Marking Guidlines"
page (There is a link to that in the Lab/Exams section). The Error
handling section explains that any irrecoverable error should "print an
error message to stdout starting with string "error:" and then terminate
the program by calling "exit(1);". It is our assumption that everyone has
read this section of the website.

2. Two posts by Alexander Smith specifically mentioned that "any special
case I have not mentioned should be treated as an error":

January 21st: "RE: Input from automarking"
January 23rd: "RE: Unexpected Input"

3. Lab1 is due on Monday, January 26th, at 23:59. There is plenty of time
left.

Feel free to ask any more questions.

Thanks and good luck!
Post by Belov Mihhail
Why are we being told this the day before the program is due?
I'm sure most people have already written the program. In my case I have
the computer asking the user for the correct input in a loop so as to
ensure number between 1 and 100 are entered.
If you want us to do some "specific" procedure during a special case you
should indicate it in the lab handout.
The reason I think it is a big deal is because a computer program is
marking our programs, which is inflexible to the style of programming we
use.
-Mike
Post by Moayad Fahim Ali
This is regarding the function computer_guess() in guess.c.
Please take into consideration the special cases when the number guessed
is greater than 100 or less than 1. Your code should generate an error
message of the form "error: ... something here ..." informing the user
that the number is impossible. The program should also terminate.
Belov Mihhail
2004-01-24 20:31:38 UTC
Permalink
I understand that the number entered out of range should be treated as
an error. However, there are different way of dealing with such a situation.

In your post you clearly tell us that you want the program to terminate
if the human entered range is not within bounds.
The website on the other hand clearly indicates that you should try
recover from an error if you can.
"It is hard to generalize how different errors
should be handled; however, if it is possible to recover from an error
try to do so without terminating."

As well, the newsgroup you indicated posts are even more conflicting
with the Jan21 giving the impression that you don't even have to error
handle the case of negative integers (computer would just tell you that
it is too low).
"- For human_guess(), the human will always enter integers. Note that
if the human is not very smart, he/she may guess a number that is out
of range, or that he/she should "know" is too high or low from a
previous guess. That is ok - the program can still tell the user that
the number is too high or too low. (I.e., if the human enters -10023,
then that is too low.)"


I realize I have misteaken the due date, however it would be nice to
know specific guidelines at the begging of the lab so that people who
wish to finish writing their programs early can do so.

I hope you can see my point about not having concrete guidelines in
writing programs while at the same time having a computer mark our
assignments for correctedness.

-Mike
Post by Moayad Fahim Ali
Hi Mike,
Whenever the user is supposed to enter input to the program, the input
should be validated for correctness. In human_guess(), the human can not
input a number that is out of bound, that should be treated as an error.
Similarly, in computer_guess(), it is an error for the human user to tell
the computer that its guess is higher than 100 or lower than 1 and should
be treated as such.
1. The "special" procedure I clarified was posted on the class website
under the Error Handling section of the "Marking Guidlines"
page (There is a link to that in the Lab/Exams section). The Error
handling section explains that any irrecoverable error should "print an
error message to stdout starting with string "error:" and then terminate
the program by calling "exit(1);". It is our assumption that everyone has
read this section of the website.
2. Two posts by Alexander Smith specifically mentioned that "any special
January 21st: "RE: Input from automarking"
January 23rd: "RE: Unexpected Input"
3. Lab1 is due on Monday, January 26th, at 23:59. There is plenty of time
left.
Feel free to ask any more questions.
Thanks and good luck!
Post by Belov Mihhail
Why are we being told this the day before the program is due?
I'm sure most people have already written the program. In my case I have
the computer asking the user for the correct input in a loop so as to
ensure number between 1 and 100 are entered.
If you want us to do some "specific" procedure during a special case you
should indicate it in the lab handout.
The reason I think it is a big deal is because a computer program is
marking our programs, which is inflexible to the style of programming we
use.
-Mike
Post by Moayad Fahim Ali
This is regarding the function computer_guess() in guess.c.
Please take into consideration the special cases when the number guessed
is greater than 100 or less than 1. Your code should generate an error
message of the form "error: ... something here ..." informing the user
that the number is impossible. The program should also terminate.
Moayad Fahim Ali
2004-01-24 23:22:19 UTC
Permalink
Hi Mike (and Hammad Imad),

I think you're confusing between computer_guess() and human_guess(). The
special case I posted was regarding computer_guess() (read the first
line) and not human_guess() (which is the one you are referring to).

Here is an example of the case I was referring to in computer_guess():

1. Computer guesses 34 -> You reply [l] (Too low)
2. Computer then guesses 69 -> You reply [l] (Too low)
3. Computer then guesses 100 -> You reply [l] (Too low)

In this error case (and also case of 1 being too high), the program should
terminate and print an error message because the user was all long
guessing a number that is out of bounds.

In another case also in computer_guess(), you could be lying to the
computer (just typing random [l]s and [h]s) but still limiting the
computers guess to within the range 1-100 (i.e., you're not telling it
that 100 is too low or 1 is too high). One possibility is that you will
eventually reach a state where there is one possible number left, the
other possibility will be that the computer is stuck at one number and
keeps asking you about it forever until you press [c] "Correct". This case
has been covered in earlier posts, please refer to them.

Now, for the error case you're referring to in human_guess(), the way you
are handling it is perfectly fine (it is recoverable). If the human
guesses less than 1 (or more than 100), the computer should reply by
saying "Too low" or "Too high" and should NOT terminate.


Hope this helps calrify the problem.

Thanks.
Post by Belov Mihhail
I understand that the number entered out of range should be treated as
an error. However, there are different way of dealing with such a situation.
In your post you clearly tell us that you want the program to terminate
if the human entered range is not within bounds.
The website on the other hand clearly indicates that you should try
recover from an error if you can.
"It is hard to generalize how different errors
should be handled; however, if it is possible to recover from an error
try to do so without terminating."
As well, the newsgroup you indicated posts are even more conflicting
with the Jan21 giving the impression that you don't even have to error
handle the case of negative integers (computer would just tell you that
it is too low).
"- For human_guess(), the human will always enter integers. Note that
if the human is not very smart, he/she may guess a number that is out
of range, or that he/she should "know" is too high or low from a
previous guess. That is ok - the program can still tell the user that
the number is too high or too low. (I.e., if the human enters -10023,
then that is too low.)"
I realize I have misteaken the due date, however it would be nice to
know specific guidelines at the begging of the lab so that people who
wish to finish writing their programs early can do so.
I hope you can see my point about not having concrete guidelines in
writing programs while at the same time having a computer mark our
assignments for correctedness.
-Mike
Post by Moayad Fahim Ali
Hi Mike,
Whenever the user is supposed to enter input to the program, the input
should be validated for correctness. In human_guess(), the human can not
input a number that is out of bound, that should be treated as an error.
Similarly, in computer_guess(), it is an error for the human user to tell
the computer that its guess is higher than 100 or lower than 1 and should
be treated as such.
1. The "special" procedure I clarified was posted on the class website
under the Error Handling section of the "Marking Guidlines"
page (There is a link to that in the Lab/Exams section). The Error
handling section explains that any irrecoverable error should "print an
error message to stdout starting with string "error:" and then terminate
the program by calling "exit(1);". It is our assumption that everyone has
read this section of the website.
2. Two posts by Alexander Smith specifically mentioned that "any special
January 21st: "RE: Input from automarking"
January 23rd: "RE: Unexpected Input"
3. Lab1 is due on Monday, January 26th, at 23:59. There is plenty of time
left.
Feel free to ask any more questions.
Thanks and good luck!
Post by Belov Mihhail
Why are we being told this the day before the program is due?
I'm sure most people have already written the program. In my case I have
the computer asking the user for the correct input in a loop so as to
ensure number between 1 and 100 are entered.
If you want us to do some "specific" procedure during a special case you
should indicate it in the lab handout.
The reason I think it is a big deal is because a computer program is
marking our programs, which is inflexible to the style of programming we
use.
-Mike
Post by Moayad Fahim Ali
This is regarding the function computer_guess() in guess.c.
Please take into consideration the special cases when the number guessed
is greater than 100 or less than 1. Your code should generate an error
message of the form "error: ... something here ..." informing the user
that the number is impossible. The program should also terminate.
Diego Huang
2004-01-25 16:59:53 UTC
Permalink
Date: Sat, 24 Jan 2004 23:22:19 GMT
Newsgroups: ut.ecf.ece242
Subject: Re: guess.c Special Case
[...]
In another case also in computer_guess(), you could be lying to the
computer (just typing random [l]s and [h]s) but still limiting the
computers guess to within the range 1-100 (i.e., you're not telling it
that 100 is too low or 1 is too high). One possibility is that you will
eventually reach a state where there is one possible number left, the
other possibility will be that the computer is stuck at one number and
keeps asking you about it forever until you press [c] "Correct". This case
has been covered in earlier posts, please refer to them.
Hi,

Would you mind explaining how the progam could get stuck in one number?
The two cases that I can think of is
1) 95 is too low, and 97 is too high --> so program guesses 96 without
prompting the user for correctedness.

2) 95 is too low, and 96 is too high --> I assume this is the case that
you and Alexander are referring to when you say that the user has to
eventually press 'c'. But I don't see how the program will keep asking
forever, 'cause it will try to generate a number between 95 and 96, not
including 95 and 96...so it's an invalid range. So I don't see how it
can get stuck at one number.

Thanks,

Diego
Al-Dhalaan Abdullah H
2004-01-26 23:20:11 UTC
Permalink
Hello,

Yes, I would also like this clarified. For the case that 92 is too low and
93 is too high (for example), my program does _not_ get stuck, rather it
sees the user guessing an integer between 92 and 93 (exclusive), which is
obviously not possible. I.e, it is handled as an error. Is this OK?

Thanks,
Abdullah Al-Dhalaan
Post by Diego Huang
Date: Sat, 24 Jan 2004 23:22:19 GMT
Newsgroups: ut.ecf.ece242
Subject: Re: guess.c Special Case
[...]
In another case also in computer_guess(), you could be lying to the
computer (just typing random [l]s and [h]s) but still limiting the
computers guess to within the range 1-100 (i.e., you're not telling it
that 100 is too low or 1 is too high). One possibility is that you will
eventually reach a state where there is one possible number left, the
other possibility will be that the computer is stuck at one number and
keeps asking you about it forever until you press [c] "Correct". This case
has been covered in earlier posts, please refer to them.
Hi,
Would you mind explaining how the progam could get stuck in one number?
The two cases that I can think of is
1) 95 is too low, and 97 is too high --> so program guesses 96 without
prompting the user for correctedness.
2) 95 is too low, and 96 is too high --> I assume this is the case that
you and Alexander are referring to when you say that the user has to
eventually press 'c'. But I don't see how the program will keep asking
forever, 'cause it will try to generate a number between 95 and 96, not
including 95 and 96...so it's an invalid range. So I don't see how it
can get stuck at one number.
Thanks,
Diego
Moayad Fahim Ali
2004-01-28 22:58:52 UTC
Permalink
Either methods are acceptable..

Moayad
Post by Chui Jimmy
Hello,
Yes, I would also like this clarified. For the case that 92 is too low and
93 is too high (for example), my program does _not_ get stuck, rather it
sees the user guessing an integer between 92 and 93 (exclusive), which is
obviously not possible. I.e, it is handled as an error. Is this OK?
Thanks,
Abdullah Al-Dhalaan
Post by Diego Huang
Date: Sat, 24 Jan 2004 23:22:19 GMT
Newsgroups: ut.ecf.ece242
Subject: Re: guess.c Special Case
[...]
In another case also in computer_guess(), you could be lying to the
computer (just typing random [l]s and [h]s) but still limiting the
computers guess to within the range 1-100 (i.e., you're not telling it
that 100 is too low or 1 is too high). One possibility is that you will
eventually reach a state where there is one possible number left, the
other possibility will be that the computer is stuck at one number and
keeps asking you about it forever until you press [c] "Correct". This case
has been covered in earlier posts, please refer to them.
Hi,
Would you mind explaining how the progam could get stuck in one number?
The two cases that I can think of is
1) 95 is too low, and 97 is too high --> so program guesses 96 without
prompting the user for correctedness.
2) 95 is too low, and 96 is too high --> I assume this is the case that
you and Alexander are referring to when you say that the user has to
eventually press 'c'. But I don't see how the program will keep asking
forever, 'cause it will try to generate a number between 95 and 96, not
including 95 and 96...so it's an invalid range. So I don't see how it
can get stuck at one number.
Thanks,
Diego
Xu Jian Phoenix
2004-01-25 17:20:24 UTC
Permalink
Hi, Moayad,
The following message is copied from an email in the newsgroup sent by
the other TA earlier.
it seems that we dont need to give any error message, instead, we just
need to say if it is too low or too high. and that is different from
what it says in your emal.
The lab is due tomorrow, please tell us which one we should follow?

thanks,
Phoenix

**************************************************
For the guessing game:
- For human_guess(), the human will always enter integers. Note that if
the human is not very smart, he/she may guess a number that is out of
range, or that he/she should "know" is too high or low from a previous
guess. That is ok - the program can still tell the user that the number is
too high or too low. (I.e., if the human enters -10023, then that is too
low.)
- For computer_guess(), the human will always enter a non-whitespace
character and press enter, but the character is not necessarily 'l', 'h',
or 'c'. (If it's not, then the comptuer should ask the question again -
see the lab handout.) It doesn't matter whether or not the human is
truthful. The way the game is designed, the computer is guaranteed
eventually to reach a state where the user enters 'c', or there is only
one possibility left.
***************************************************************
Post by Moayad Fahim Ali
This is regarding the function computer_guess() in guess.c.
Please take into consideration the special cases when the number guessed
is greater than 100 or less than 1. Your code should generate an error
message of the form "error: ... something here ..." informing the user
that the number is impossible. The program should also terminate.
Moayad Fahim Ali
2004-01-25 18:17:41 UTC
Permalink
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!
Moayad Fahim Ali
2004-01-25 18:49:14 UTC
Permalink
Hi,

As mentioned by Alexander on January 20th "Lab 1 guess. c - when only one
possibility remains":

The computer should tell the user the number is 50 and should end the
game. It should not ask the user again if 50 is correct or not.

Hope this helps.
Hi,
Thanks for the post. However, I still have concerns about point (2), when
the computer narrows down to the number 50 (after guess 49 and 51), should
it keep telling the user the number is 50 until a [c] is entered, or
should it terminate after saying your number is 50.? Thanks!
Chui Jimmy
2004-01-25 22:52:21 UTC
Permalink
Hello,

I have just realized that if you type in a letter instead of a number the
guessing game would go nuts, say the number is too high.

I wonder if that is an error we have to curb.,??

thanks.
Moayad Fahim Ali
2004-01-26 02:46:39 UTC
Permalink
Hi,

This question was answered in a post by Alexander Smith on January 21st
titled "Re: Input from automarking".
Post by Chui Jimmy
Hello,
I have just realized that if you type in a letter instead of a number the
guessing game would go nuts, say the number is too high.
I wonder if that is an error we have to curb.,??
thanks.
Lu Daniel Hao
2004-01-25 18:31:31 UTC
Permalink
Hi,

Thanks for the post. However, I still have concerns about point (2), when
the computer narrows down to the number 50 (after guess 49 and 51), should
it keep telling the user the number is 50 until a [c] is entered, or
should it terminate after saying your number is 50.? Thanks!
Continue reading on narkive:
Loading...