Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 3. Write a program to play a lottery game. A player gets to play 5 times (per round) to try and guess the super

Exercise 3. Write a program to play a lottery game. A player gets to play 5 times (per round) to try and guess the super jackpot. The program generates a random two-digit number and prompts the player to input their two-digit guess. The player gets 5 chances in each round of the game. For each guess, the rules to determine the winnings are:

- If the two digits match exactly the random number (in the right order), the player wins the super jackpot ($1000).

- If the two digits match (but not in the right order), the player wins $10.

- If one digit matches, the player wins $1.

After a round of play (5 turns), print out the total winnings and ask the user if they want to play again (and if so, print the winnings over all rounds and start a new round of play). If they want to stop playing, print the total winnings over all rounds and the best round winnings (e.g., if they play four rounds and round two had the highest winnings, then print those winnings).

See below for a description of random number generation.

Provide:

- Printout of properly formatted source code

- Example output/test cases (2 test cases with at least 3 rounds each different than shown).

A sample run:

Welcome to the Super Lottery!

Let's Play!

Round 1 - you have 5 chances to win money

Enter your guess: 34

The lottery number is 24

You guessed one number! You win $1!

Enter your guess: 21

The lottery number is 12

You guessed both numbers, but in a different order! You win $10!

Enter your guess: 11

The lottery number is 90

Good luck next time! You still have 2 guesses.

Enter your guess: 42

The lottery number is 42

CONGRATULATIONS! You win the Super Jackpot! $1000!

Enter your guess: 22

The lottery number is 26

You guessed one number! You win $1!

End of round. You won $1012

Play again? (enter yes/no): yes

Total winnings over 1 rounds is $ 1012

Let's play again!!!

Round 2 - you have 5 chances to win money

Enter your guess: 87

The lottery number is 77

You guessed one number! You win $1!

Enter your guess: 65

The lottery number is 87

Good luck next time! You still have 3 guesses.

Enter your guess: 22

The lottery number is 13

Good luck next time! You still have 2 guesses.

Enter your guess: 90

The lottery number is 29

You guessed one number! You win $1!

Enter your guess: 35

The lottery number is 40

Good luck next time!

End of round. You won $2

Play again? (enter yes/no): yes

Total winnings over 2 rounds is $ 1014

Let's play again!!

Round 3 - you have 5 chances to win money

Enter your guess: 38

The lottery number is 38

CONGRATULATIONS! You win the Super Lottery! $1000!

Enter your guess: 98

The lottery number is 47

Good luck next time! You still have 3 guesses.

Enter your guess: 20

The lottery number is 28

You guessed one number! You win $1!

Enter your guess: 21

The lottery number is 12

You guessed both numbers, but in a different order! You win $10!

Enter your guess: 33

The lottery number is 88

Good luck next time!

End of round. You won $1011.0

Play again? (enter yes/no): no

Total winnings over 3 rounds is $ 2025

Top round: Round 1 winnings $ 1012

Goodbye!

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 Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

What is white noise?

Answered: 1 week ago

Question

1. Describe a comprehensive approach to retaining employees.pg 87

Answered: 1 week ago

Question

Understand how to design effective service guarantees.

Answered: 1 week ago

Question

Know when firms should not offer service guarantees.

Answered: 1 week ago