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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started