Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2- It will be important to understand how random numbers are generated using the rand() function. You will also need to have a basic understanding

image text in transcribed
2- It will be important to understand how random numbers are generated using the rand() function. You will also need to have a basic understanding of a while or for loop (look for file "Ch08_LogicalFunctionsTotal "in D2L->contents->Matlab Presentation and HW You are to write a program in which the user tries to guess which number (from 1 to 7, inclusive) that the program generates, based on the rand() function. The first the program asks the user to guess which number will be generated, and if the user is correct, it prints"Good guess!" and if the user is incorrect, it prints "Sorry, try again!" Some other specifications: 1. The program should repeatedly ask the user for a guess, and repeatedly generates a new random number between 1 and 7, and outputs "Number picked: "followed by the number, and the statements as to whether it was correct or not. 2. 2. If the user enters a number of 0 or less, the program should print "Goodbye" and exit. 3. If the user enters a number greater than 7, the program should output "Number too high, guess again!" and then ask for another number. In this last case, no new random number should be generated. Below is a sample output from an execution of the program. In the sample output examples that follow the user input appears after the colon character () and is followed by the enter key Guess a number from 1to 7 (-0 to quit):5 Number picked: 2 Sorry, try again! Guess a number from 1 to 7 (-0 to quit): 7 Number picked: 7 Good guess! Guess a number from 1to 7 (-0 to quit):4 Number picked: 4 Good guess! Guess a number from 1 to 7 (

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_2

Step: 3

blur-text-image_3

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions