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:
Output for this project:
Processing Requirements
For example if array1 and array2 contain the following values:
array1: 12 3 60 4
array2: 60 12 4 5
Then calling the function compareArrays(arra1,array2,4) should return 3.
4. A function called displayArray that takes two arguments, an int array and an int for the size of the array and displays the content of the array. This function does not return anything.
---------------------I used Visual Studio 2013, C++ Lang, Console App------------
I am new to Powerball game, So i went to their website and understood how the game works, If you don't know just google powerball game rules.
---------------Screenshot----------------
----------------CODE---------------------
// Powerball.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h>
#include <thread> // std::this_thread::sleep_for
#include <chrono>
using namespace std;
int arrayOfFiveNumber[5];
int redBall;
int computer5GeneratedNumber[5];
int computer1GeneratedNumber;
int redballcount = 0;
int getArandNum(int min, int max)
{
///* initialize random seed: */
srand(time(NULL));
//Waiting one second to avoid getting the same number
again and again
std::this_thread::sleep_for(std::chrono::seconds(1));
return rand() % max + min;
}
void selfPick()
{
cout << "Choose five white ball numbers between
1 and 69 : " << endl;
for (int i = 0; i < 5; i++)
cin >>
arrayOfFiveNumber[i];
cout << "Please wait while generating..."
<< endl;
for (int j = 0; j < 5; j++)
computer5GeneratedNumber[j] =
getArandNum(1, 69);
cout << "Choose one red ball number between 1
and 26 : "<<endl;
cin >> redBall;
computer1GeneratedNumber = getArandNum(1, 26);
if (computer1GeneratedNumber == redBall)
redballcount++;
}
void autoPick()
{
cout << "Please wait while generating..."
<< endl;
for (int i = 0; i < 5; i++)
arrayOfFiveNumber[i] =
getArandNum(1, 69);
for (int j = 0; j < 5; j++)
computer5GeneratedNumber[j] =
getArandNum(1, 69);
cout << "Automatically generated user five White
ball numbers between 1 and 69" << endl;
redBall = getArandNum(1, 26);
computer1GeneratedNumber = getArandNum(1, 26);
cout << "Automatically generated user one Red
ball number between 1 and 26" << endl;
if (computer1GeneratedNumber == redBall)
redballcount++;
}
int compareArrays(int userArray[5],int computerArray[5], int
size)
{
int count = 0;
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size;
j++)
{
if
(userArray[i]==computerArray[j])
{
count++;
}
}
}
return count;
}
void sortArray(int userArray[5])
{
int mini, temp;
for (int r1 = 0; r1<4; r1++)
{
mini = r1;
for (int r2 = r1 + 1; r2<5;
r2++)
if
(userArray[r2]<userArray[mini])
mini = r2;
if (mini != r1)
{
temp =
userArray[r1];
userArray[r1] =
userArray[mini];
userArray[mini]
= temp;
}
}
}
void displayArray(int userArray[5], int size)
{
for (int q = 0; q<size; q++)
{
cout << userArray[q] <<
" ";
}
cout << endl;
}
void result(int whiteballcount,int redballcount)
{
cout << "Correct white ball : " <<
whiteballcount << endl;
cout << "Correct red ball : " <<
redballcount << endl;
if (whiteballcount == 5 && redballcount ==
1)
cout << "You won prize :
$1,000,000,000.00" << endl;
else if (whiteballcount == 5 )
cout << "You won prize : $1
Million" << endl;
else if (whiteballcount == 4 && redballcount
== 1)
cout << "You won prize :
$50,000" << endl;
else if (whiteballcount == 4 )
cout << "You won prize :
$100" << endl;
else if (whiteballcount == 3 &&
redballcount==1)
cout << "You won prize :
$100" << endl;
else if (whiteballcount == 3)
cout << "You won prize : $7"
<< endl;
else if (whiteballcount == 2 && redballcount
== 1)
cout << "You won prize : $7"
<< endl;
else if (whiteballcount == 1 && redballcount
== 1)
cout << "You won prize : $4"
<< endl;
else if (redballcount == 1)
cout << "You won prize : $4"
<< endl;
else
cout << "Better luck next
time" << endl;
}
int main()
{
int choice,whitecount;
cout <<
"===============Powerball===============" << endl;
cout << "Select five numbers from 1 to 69 for
the white balls; then select one number from 1 to 26 for the red
Powerball." << endl;
cout << "Players win a prize by matching one of
the 9 Ways to Win :: " << endl;
cout << "If you got correct 5 white ball and 1
red ball, Prize : $1,000,000,000.00" << endl;
cout << "If you got correct 5 white ball, Prize
: $1 Million" << endl;
cout << "If you got correct 4 white ball and 1
red ball, Prize : $50,000" << endl;
cout << "If you got correct 4 white ball, Prize
: $100" << endl;
cout << "If you got correct 3 white ball and 1
red ball, Prize : $100" << endl;
cout << "If you got correct 3 white ball, Prize
: $7" << endl;
cout << "If you got correct 2 white ball and 1
red ball, Prize : $7" << endl;
cout << "If you got correct 1 white ball and 1
red ball, Prize : $4" << endl;
cout << "If you got correct 1 red ball, Prize :
$4" << endl;
cout << endl;
cout << "Enter the Game mode, <1> Self
pick <2> Auto pick : ";
cin >> choice;
switch (choice)
{
case 1:
cout << "You choosed Self
pick." << endl;
selfPick();
whitecount =
compareArrays(arrayOfFiveNumber, computer5GeneratedNumber,5);
result(whitecount,
redballcount);
break;
case 2:
cout << "You choosed Auto
pick." << endl;
autoPick();
whitecount =
compareArrays(arrayOfFiveNumber, computer5GeneratedNumber,5);
result(whitecount,
redballcount);
break;
default:
cout << "Please choose the
correct option." << endl;
break;
}
cout << "Sorted user White ball numbers : "
<< endl;
sortArray(arrayOfFiveNumber);
displayArray(arrayOfFiveNumber,5);
cout << "Sorted winning White ball numbers : "
<< endl;
sortArray(computer5GeneratedNumber);
displayArray(computer5GeneratedNumber,5);
cout << "User input Red ball number : " <<
redBall << endl;
cout << "Winning Red ball number : " <<
computer1GeneratedNumber << endl;
cin >> choice;
return 0;
}
Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...
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...
Write a program to merge two sorted arrays into a third array. Ask the user to enter the size of the two arrays. The length of array1 could be greater than, equal to or less than the length of array2. Fill both with random numbers 0-99. Sort both arrays as explained below. Write a method merge that takes the two arrays as arguments. The method returns a merged array with size equal to the size of both arrays combined. Note:...
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...
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...
Write a C program that inputs 5 elements into each of 2 integer arrays. Add corresponding array elements, that array1 [0] + array2[0], etc. Save the sum into a third array called sumArray[]. Display the sum array. Submit your and the input and output of the complete execution.
In C... Write a program to simulate a pick-5 lottery game. Your program must generate and store 5 distinct random numbers between 1 and 9 (inclusive) in an array. The program prompts the user for: an integer random seed five distinct integers between 1 and 9 (which are stored in another array) The program then compares the two arrays to determine if they are identical. If the two arrays are identical, then the user wins the game. otherwise the program...
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...
I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...
Question: In C++ Write a correct and complete C++ program th... Bookmark In C++ Write a correct and complete C++ program that inputs 20 integer values from the user and performs three calculations. In the main function, input the values from the user. As part of your answer, write a sub-function, named calcAvg (), which takes two arguments and returns the average of all the integers. Also write another sub-function, named reverseArray (), which takes two arguments and reverses the...
C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...