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.
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.
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.
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.
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.
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.
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?