Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

First, the program prints an introduction in the form of a haiku poem. Recall that a haiku has 3 lines: one with 5 syllables, the

image text in transcribed

image text in transcribed

First, the program prints an introduction in the form of a haiku poem. Recall that a haiku has 3 lines: one with 5 syllables, the second with 7 syllables, and the third with 5 syllables.

Next, a series of guessing games is played. In each game, the computer chooses a random number between 1 and 100 inclusive. The game asks the user for guesses until the correct number is guessed. After each incorrect guess, the program gives a clue about whether the correct number is higher or lower than the guess. Once the user types the correct number, the game ends and the program reports how many guesses were needed.

After each game ends and the number of guesses is shown, the program asks the user if he/she would like to play again. Assume that the user will type an integer as a response to this question.

A new game should begin if the user's response is any positive number greater than 0. For example, answers such as 4, 1, 9843, 42, 0001, or 90000 all indicate that the user wants to play again. Any other response means that the user does not want to play again. For example, responses of -1, -1432, 0000, 0, and -123 are all assumed to mean no.

Once the user chooses not to play again, the program prints overall statistics about all games. The total number of games, total guesses made in all games, average number of guesses per game (as a real number rounded to the nearest tenth), and best game (fewest guesses needed to solve any one game) are displayed.

Your statistics should be correct for any number of games or guesses 1. You may assume that no game will require one million or more guesses.

You should handle the special case where the user guesses the correct number on the first try. Print a message as follows:

image text in transcribed

Define a class constant for the maximum number used in the games. The previous page's log shows games from 1 to 100, but you should be able to change the constant value to use other ranges such as from 1 to 50 or any maximum.

image text in transcribed

Produce repetition using while loops. You may also want to review fencepost loops and sentinel loops from week 4. Lecture 14's adding_game.c is a relevant example. Some students try to avoid properly using while loops by writing a function that calls itself, or a pair of functions A and B where A calls B and B calls A, creating a cycle of calls. Such solutions are not appropriate on this assignment and will result in a deduction. You are also forbidden from using break and continue statements.

image text in transcribed

PLEASE TYPE IN C. MY INSTRUCTOR WON'T ALLOW IN C++, C+ OR JAVA. C ONLY!!!!

This assignment focuses on while loops and random numbers. Turn in a file named guessing_game.c. Your program allows the user to play a game in which the program thinks of a random integer and accepts guesses from the user until the user guesses the number correctly. After each incorrect guess, you will tell the user whether the correct answer is higher or lower. Your program must exactly reproduce the format and behavior of the logs in this document. The log below shows one sample execution of your program. Your output will differ depending on the random numbers chosen and user input typed, but the overall output structure should match that shown below. your haiku intro message here >> I'm thinking of a number between 1 and 100... Your guess? 50 It's lower. Your guess? 25 It's higher. Your guess? 35 It's lower Your guess? 30 It's higher. Your guess? 32 It's lower Your guess? 31 You got it right in 6 guesses! Do you want to play again? 1 I'm thinking of a number between 1 and 100... Your guess? 50 It's higher Your guess? 75 It's lower. Your guess? 65 It's lower. Your guess? 64 You got it right in 4 guesses ! Do you want to play again? 42 I'm thinking of a number between 1 and 100... Your guess? 60 It's lower. Your guess? 20 It's higher. Your guess? 30 It's higher. Your guess? 40 It's higher. Your guess? 50 It's lower Your guess? 47 It's higher. Your guess? 49 You got it right in 7 guesses! Do you want to play again? O Overall results: Total games = 3 Total guesses = 17 Guesses/game = 5.7 Best game = 4 I'm thinking of a number between 1 and 100... Your guess? 71 You got it right in 1 guess! your haiku intro message here >> I'm thinking of a number between 1 and 5... Your guess? 2 It's higher. Your guess? 4 It's lower. Your guess? 3 You got it rght in 3 guesses! Do you want to play again? 345345345 I'm thinking of a number between 1 and 5... a 1 Your guess? 3 It's higher. Your guess? 5 You got it right in 2 guesses! Do you want to play again? -234324 Overall results: Total games = 2 Total guesses = 5 Guesses/game = 2.5 Best game = 2 2 I'm thinking of a number between 1 and 100... *** HINT: The answer is 46 Your guess? 50 It's lower. Your guess? 25 It's higher. Your guess? 48 It's lower. Your guess? 46 You got it right in 4 guesses! (suggested initial simple version of program)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions

Question

=+4 How does one acquire a global mindset?

Answered: 1 week ago

Question

=+2 How can the effectiveness of global virtual teams be improved?

Answered: 1 week ago