Question

c++ please help You are going to create a PowerBall Lottery game with functions. First, you...

c++ please help

You are going to create a PowerBall Lottery game with functions. First, you are going to generate 5 UNIQUE numbers between 1 and 69. Then you are going to generate the powerball number, which is a number between 1 and 26. Next you are going to ask the user for 5 numbers. Users should only be allowed to enter numbers in the range 1-69 for regular numbers, 1-26 for powerball pick. You will compare each of the user's numbers to the numbers chosen for the lottery. Then you are going to ask the user for their powerball number guess. You will compare the value of the user powerball number to the computer powerball number. You will output: the lottery numbers, the user numbers, and the number of powerball numbers the user picked correctly. You will output if the user got the powerball correct. You will use functions that have functional signatures given below: int randBetween(int min, int max) // calculate a random # between min and max int getValue() // returns a user entered value bool isSame(int newNumber, int number) // returns true if newNumber is the same as number bool isInBounds(int number, int min, int max) // returns true if the number is between min and max (inclusive) void printNumbers(int number1, int number2, int number3, int number4, int number5, int powerball) // prints the powerball and user numbers as 53 24 3 7 33 POWERBALL 5 Student Learning Outcomes: Use function prototypes to create functions Use functions Algorithm design Loops Conditionals Pass-by-copy

0 0
Add a comment Improve this question Transcribed image text
Answer #1

​​​​

Formatting code in text:

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int randBetween(int min, int max); // calculate a random # between min and max

int getValue(); // returns a user entered value

bool isSame(int newNumber, int number); // returns true if newNumber is the same as number

bool isInBounds(int number, int min, int max); // returns true if the number is between min and max (inclusive)

void printNumbers(int number1, int number2, int number3, int number4, int number5, int powerball); // prints the powerball and user numbers as 53 24 3 7 33 POWERBALL 5

int main() {

// array for powerball nos

int lotteryNos[5];

int PowerBall;

// randomly generate unique power ball nos

srand(time(NULL));

int prevNumber = 0;

for (int i = 0; i < 5; i++) {

lotteryNos[i] = randBetween(1, 69);

if (isSame(lotteryNos[i], prevNumber))

i--;

prevNumber = lotteryNos[i];

}

PowerBall = randBetween(1, 26);

// ask user for numbers

int userNos[5], userPowerBall = 0;

cout << "Enter 5 numbers in range 1-69.\n";

int i = 0;

while (i < 5) {

int num;

cout << "Enter number: ";

cin >> num;

if (isInBounds(num, 1, 69)) {

userNos[i] = num;

i++;

}

else

cout << "Inavlid. Enter again.\n";

}

while(true) {

cout << "Enter powerball number (1-26): ";

cin >> userPowerBall;

if (isInBounds(userPowerBall, 1, 26))

break;

else

cout << "Invalid. Enter again.\n";

}

// check no of correct guess by user

int correctGuess = 0;

for (int i = 0; i < 5; i++) {

if (isSame(lotteryNos[i], userNos[i]))

correctGuess++;

}

// output the result of game

cout << "Output:\n";

cout << "The lottery numbers are: \n";

printNumbers(lotteryNos[0], lotteryNos[1], lotteryNos[2], lotteryNos[3], lotteryNos[4], PowerBall);

cout << "The user numbers are: \n";

printNumbers(userNos[0], userNos[1], userNos[2], userNos[3], userNos[4], userPowerBall);

cout << "User picked correctly: " << correctGuess << " numbers.\n";

if (isSame(PowerBall, userPowerBall))

cout << "You got the powerball correctly!!";

else

cout << "You didn't got the powerball!";

return 0;

}

// calculate a random # between min and max

int randBetween(int min, int max) {

int randNo = min + (rand() % (max - min + 1));

return randNo;

}

// returns a user entered value

int getValue() {

int number;

cin >> number;

return number;

}

// returns true if newNumber is the same as number

bool isSame(int newNumber, int number) {

return newNumber == number;

}

// returns true if the number is between min and max (inclusive)

bool isInBounds(int number, int min, int max) {

if (number < min || number > max)

return false;

else

return true;

}

// prints the powerball and user numbers as 53 24 3 7 33 POWERBALL 5

void printNumbers(int number1, int number2, int number3, int number4, int number5, int powerball) {

cout << number1 << " " << number2 << " " << number3 << " " << number4 << " " << number5<< " POWERBALL " << powerball << "\n";

}

Sample output:

Add a comment
Know the answer?
Add Answer to:
c++ please help You are going to create a PowerBall Lottery game with functions. First, you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program...

    Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...

  • Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery...

    Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery game, the player picks a set of numbers. A random drawing of numbers is then made, and the player wins if his/her chosen numbers match the drawn numbers (disregarding the order of the numbers). More specifically, a player picks k distinct numbers between 1 and n (inclusive), as well as one bonus number between 1 and m (inclusive). "Distinct" means that none of the...

  • Please help to solve question 1 and subsections 1-4 1: Powerball Consider the multi-state lottery Powerball...

    Please help to solve question 1 and subsections 1-4 1: Powerball Consider the multi-state lottery Powerball game. Each ticket is $2 and allows a player to select 5 white balls from 1 to 69 (without replacement), and 1 Red Powerball, from 1 to 26. The order of the five white balls does not matter when evaluating a win. If there are 64 losing whiteball numbers, how many ways can the winner pick 4 of them. If the player is only...

  • This is for a C# program. I would greatly appreciate any help! Thank you:) For this...

    This is for a C# program. I would greatly appreciate any help! Thank you:) For this assignment you're going to create a console application called A02PBallGenerator. This app is going to mimic a quick pick program in a lotto terminal. When the user runs your app you're going to select the numbers for them. Then you'll ask them if they'd like another set of numbers. Y for yes and N for No Use a do while loop so that if...

  • Exercise 2 Write a program that simulates the Texas Powerball lottery. You will have to do resear...

    I HAVE A PROBLE WITH THIS JAVA PROBLEM CAN ANYONE HELP ME PLEASE. Exercise 2 Write a program that simulates the Texas Powerball lottery. You will have to do research to find out how many numbers are drawn, and what the range(s) of the numbers are. For this exercise you need to create a class called "Powerbali", which exposes a public function called play'. This function accepts several parameters , which represent the individual numbers the player wants to play....

  • Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive...

    Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...

  • Write a C++ program that simulates a lottery game. Your program should use functions and arrays....

    Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...

  • Please post screenshots only File Tools View CMSC 140 Common Projects Spring 2019(1) E - 3...

    Please post screenshots only File Tools View CMSC 140 Common Projects Spring 2019(1) E - 3 x Project Description The Powerball game consists of 5 white balls and a red Powerball. The white balls represent a number in the range of 1 to 69. The red Powerball represents a number in the range of 1 to 26. To play the game, you need to pick a number for each ball in the range mentioned earlier. The prize of winning the...

  • Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If...

    Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If you do actually win the lottery, please be sure to give back to your alma mater, Orange Coast College. We will be happy to put your name on the building!**) Ok, time to get real. The Fantasy 5 (TM) lottery is a game in which 5 numbers from 1 to 36 are randomly drawn by the State of California. If you correctly guess all...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT