Question
I need a c++ code for this. I'm not even sure what this program is supposed to do yet, so an example code of what
I need a c++ code for this. I'm not even sure what this program is supposed to do yet, so an example code of what something like this should look like would be great!
A simple lottery is being proposed to The Pennsylvania Lottery. The premise is this:
Each play costs $1.
To play, pick a number between 1 and 1000.
If your number matches the randomly selected number, you win $400. Otherwise, you win nothing.
The question The Pennsylvania Lottery has is, "In the long run, how much will Pennsylvania retain for each dollar spent on a ticket?" To answer this question, you will simulate playing the lottery for a year numerous times and compute/report the average amount retained.
Your program should do the following:
Prompt the user for the number of simulations to do. Each simulation represents a year worth of playing. So, the user's value indicates the number of years you are playing the game. Note: Larger numbers are better, but how large is large enough to get a consist answer? Try different large values.
If the user enters a non-positive number, display a message that the number must be positive and re-prompt. Continue to re-prompt until a positive number is entered.
Simulate the following for the user-entered number of years, assuming you have to play all 365 days a year (ignore leap years).Every day,
Pick a number that represents the player's guess (the computer should do this randomly).
Generate the winning number (again, randomly).
If the numbers match, the player wins $400. Otherwise, they don't receive anything.
Compute the average daily winnings.
At the end, compute the average winnings based on all the years. This is done by accumulating all the years' average daily winnings and dividing it by the total number of simulations run.
Remember: The goal is to know how much The Pennsylvania Lottery will retain per ticket sold! That is what your program should report.
A run of your program should look as follows:
Running simulation.......... The expected income per dollar spent on tickets is $XXXX.
where your program will replace XXXX with the answer and should be between $0.00 and $1.00.
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