CSci A201/A597
Frequently Asked Questions on Lab #5


General Questions

  1. I am having lots of trouble with the if-else statements. What do I do?

    Please see the suggestions in the class notes for Feb 25. Be particularly aware of properly indenting the code and using curly brackets whereever appropriate.

  2. Can I use a {for loop, new function or method, return statements, exit statements} etc. in my program?

    If you don't understand the above question, you are okay, so skip right by it. These are programming tecnhiques we have not learned in this class, so they should be avoided as much as possible. We will be using these a lot in upcoming assignments, so hold your horses. I can not guarantee that you will not be penalized if you use them. Some of the problems are graded based on the existence of particular programming constructs, so if your advanced programming techniques do away with the constructs we are looking for, you may get points knocked off your assignment.

    So, in brief, DO NOT USE THEM.

  3. Well then, how do I make the program exit early when the user makes the correct guess?

    You can not make the program exit early, but you can make sure that the part of the program that follows does not get executed by placing it inside an if statement. You can use a nested if statement for this, or a boolean variable that you set when a correct answer is reached and compare before you go to the next step.


Questions About Youguess.java

  1. Should we bother to make sure that the user actually follows the hints from the program?

    If you want to, that should be great, and you may even see yourself get some other mistakes ignored if you do. But the problem statement does not explicitly say this, so if a user is being stupid and selects 8 even after the program said their previous selection (say, 6) was too big, it is their problem.


Questions About Iguess.java

  1. Should we worry about checking the users' response? i.e., if the user types in an invalid option or the option in uppercase?

    As before, by all means do so if you are able, but since the assignment is not explicit about this, you do not necessarily have to handle the situations.

  2. Please please please, can you give me a hint on the strategy to use to find the answer in 4 tries?

    The strategy is very simple actually. At ever step, you want to reduce the possibilities to half of the number of possibilities in the previous step. So, start from the middle. If that is too small, take the middle value of the bigger set (and the reverse if it is too big). Continue this way - notice that you can divide 15 by 2 only 4 times before you only have 1 option.

  3. Are we supposed to have the computer generate random guess each time or should we assign the program to guess 8 first and then 12 if that is too small or 4 if that is too big?

    Maybe I did not make this very clear in the answer above. The strategy discussed above would essentially indicate that the computer's guess will start with 8, and then go down or up based on how you react to it. But this is just a strategy, although probably the only one that is guaranteed to get to the solution within 4 tries. If you generate random guesses, you may not be guaranteed to make it in 4 tries. If you can come up with a strategy using which you can get to the solution in 4 tries every time, go for it. But the above is the simplest strategy to think about (and program).

    Does that make somewhat better sense?


Last modified: Tue Mar 2 22:09:55 EST 1999