Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

While loop, and if-else-statement In this project, you will write a program to play a guessing game with the user. The program should randomly generate

image text in transcribed
image text in transcribed
image text in transcribed
While loop, and if-else-statement In this project, you will write a program to play a guessing game with the user. The program should randomly generate an integer between 1 and 100, and then ask the user to try to guess the number. If the user guesses incorrectly, the program should ask them to try again until the guess is correct; when the guess is correct, the program should print a congratulatory message (See page 996 of the textbook for description of functions rand 0 and srand(int)). Follow steps below to develop your program: - Use the randO function and the modulo operator %) to generate a random number between 1 and 100 inclusive (this is the target value). -Ask the user to guess the number and read in the value (this is the guess value). -Add a while-loop where the loop is entered only if the guess value is incorrect (i.e., the guess value is not equal to the target value). If the guess is incorrect, give them a hint and then ask them to reenter the value. If the guess is correct, end the loop and print a congratulatory message (e.g., You guessed correctly) before ending the program. Each time through the loop do the following: If the value entered by the user is greater than the target value print The number is lower. Try again. If the value entered by the user is less than the target value print: The number is higher. Try again. Prompt for and read in the value of the new guess SAMPLE OUTPUT: (Assming target is set to 57): Programmer: your name goes here Course Lab: Due Date: 3-20-2018 COSC 246, Winter 2018 Take Home Project #1 , part 1 Guess a number between 1 and 100: 80 The number is lower. Try again. Guess a number between 1 and 100: 30 The number is higher. Try again. Guess a number between 1 and 100: 60 The number is lower. Try again Guess a number between 1 and 100: 57 You guessed correctly

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

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions