Question: Write a number guessing game: Step 1: The game creates a n array of 3 integers and fills each element with a random number between

Write a

number

guessing game:

Step 1:

The game

creates

a

n array

of

3

integers

and

fills each element

with a

random number

between

1 to

5

.

Use a

for

loop for fillin

g the array

.

Step 2:

The game asks the player to enter a number. If th

e entered number is in

the array, then the game prints "You Win!". Ot

herwise, it prints "Try Again!" and

asks for another number until the player wins.

Step 3:

When the player wins, the game stops, and prints the cont

ents of the array

on the screen using

another

for

loop.

Bonus:

When creating the array, make sure each number

is

unique.

Example Output:

Guess a number (1 to

5

):

1

Try Again!

4

Try Again!

2

You Win!

The numbers were:

2

5 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!