Homework #14 (Due: Mon 02 Mar)
Modify the program you wrote for homework #10 so that it
is designed in modular fashion using methods. In particular you will
write three methods (in addition to main()) as explained below:
- Write a method that will have the user enter a guess in the range
1 to 100. The method should use a loop to validate the user input
and should return the value they enter.
- Write a similar method that will have the user enter ``y'' or
``n''. The method should return the value they enter but should
use a loop to require re-entry until one of those two values has
- Write a method that will actually play the game. This includes
selecting the hidden number and a loop of user guesses.
When you have finished the program, main() should look something like this:
call method to play the game
ans= call method to see if they want to play again
} while (ans is "y");
If you are not sure where to get started then try following these steps.
Do no proceed to the ``next'' step until you have finished the one before
it. If you get stuck then get help ... but make sure that you are
the problem-solver behind each statement!
- Create and test a method that has the user enter a guess in
the range 1 to 100. The method should return the value entered
by the user.
- Create and test a method that has the user enter a ``y'' or an
``n'' and validates the input. The method should return the value entered
by the user.
- The program that houses these two programs can be temporarily ``set
aside'' as you continue these steps.
- Make a copy of your most recent working guessing game program.
- Fix any indentation/documentation shortcomings in the program.
- Move the code that actually plays the game into a new method.
Be sure to move necessary variable declarations with it. Then
call that method from main. Compile and test!
- Take some time to look at each variable you've declared. Remove
any unncessary variables.
- Copy and paste the methods you wrote in the first steps into
this program. Compile to make sure that the methods are in the
correct location. (You won't even be using them at this point.)
- Modify the program so that it calls each of the methods when
appropriate. Compile and test.
- Make sure all indentation and documentation is up to spec. Compile
When turning in your program, you should bring a printout of your source
code to class. In addition you should email a copy of your source code
to the homework account.
Recall that each method should have a description of it's purpose as part
of the documentation.
Your program will be graded according to the following criteria: