Microsoft Word - ProgrammingAssignment2.docx Object Oriented Programming I Number Guess – Loop Programming Assignment In this assignment you are going to program a number guessing game in which you...

Just need code


Microsoft Word - ProgrammingAssignment2.docx Object Oriented Programming I Number Guess – Loop Programming Assignment In this assignment you are going to program a number guessing game in which you have 10 chances to guess a number between 1 and 100. A sample run is show below: In the program you will need a random number between 1 and 100. Review the section on generating random numbers in your text. Just because a block of code has a definite number of iterations doesn’t mean that you need to use a for loop. The fact that you have ten guesses may lead you to think that you need ten iterations. But you might guess the number your first try. So, you can’t tell how many iterations you are going to need when you start the game. Therefore, this program can be more naturally written with a while or do - while loop. In this program you are going to use a Boolean variable to control the main loop. You should review the section in your text that discusses using Boolean variables as sentinel values. Your program should only accept integers between 1 and 100. Review the section on do-loops in your text for an example of how to do this. If the user tries to guess a number outside of this range, you should print an error message and reprompt the user for a guess. Notice that an out-of-range guess does not count against the number of guesses. In order to practice different types of loops, we are imposing a structural constraint on this problem. This program requires a nested loop structure. The inner loop is a do-while loop that checks to make sure the user enters a valid value. The outer (main) loop is a while (!done) loop that controls the game using the Boolean variable done. This means you are not free to write this program anyway you please. Programs that do not use this structure will not meet specifications and will have to be redone. In other words, your main method should have the following structure (pseudocode): while (not done) { do { get and validate a guess } while (not valid) Logic to process guess } If the player loses the game, you should print a message and display the number. 2
Oct 07, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here