Question

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 baFile Tools View CMSC 140 Common Projects Spring 2019(1) E - 5 x • One number between 1 and 26 for the red ball (if game modeFile Tools View CMSC 140 Common Project Spring 2019(1) E - 3 x Then calling the function compare Ar- rays(arral, array2,4) sh

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

Screenshot

- deepthi.onganattu - D File Solution Server Explorer Toolbox PowerballGameInCpp - Microsoft Visual Studio Quick Launch (CtrlProgram

//Header files
#include <iostream>
#include<iomanip>
using namespace std;
//Grand prize
#define GRANDPRIZE 1000000000.00

//Function prototypes
void titleRules();
int getArandNum(int, int);
void sortArray(int*,const int);
int compareArrays(const int[], const int[],const int);
void displayArray(const int[], const int);
double getPoints(const int,const char);

int main()
{
   char ch;
   int playerBalls[6], winBalls[6];
    //Title and rule display
   titleRules();
   //Generate winning numbers
   for (int i = 0; i < 5; i++) {
       winBalls[i] = getArandNum(1, 69);
   }
   winBalls[5] = getArandNum(1, 26);
   //Option for white ball entry for user
   cout << "Do you want to self pick your white balls(Y or N): ";
   cin >> ch;
   ch = toupper(ch);
   while (ch != 'Y' && ch != 'N') {
       cout << "Incorrect choice!!!enter again" << endl;
       cout << "Do you want to self pick your white balls(Y or N): ";
       cin >> ch;
       ch = toupper(ch);
   }
   //Self entry
   if (ch == 'Y'){
       for (int i = 0; i < 5; i++) {
           cout << "Enter a number "<< (i + 1)<<"(between 1 to 69): " << ": ";
           cin >> playerBalls[i];
           while (playerBalls[i] < 1 || playerBalls[i]>69) {
               cout << "Enter a number " << (i + 1) << "(between 1 to 69): " << ": ";
               cin >> playerBalls[i];
           }
       }
   }
   //Otherwise
   else {
       for (int i = 0; i < 5; i++) {
           playerBalls[i] = getArandNum(1, 69);
       }
   }
   //Option for power ball entry
   cout << "Do you want to self pick your red ball(Y or N): ";
   cin >> ch;
   ch = toupper(ch);
   while (ch != 'Y' && ch != 'N') {
       cout << "Incorrect choice!!!enter again" << endl;
       cout << "Do you want to self pick your red ball(Y or N): ";
       cin >> ch;
       ch = toupper(ch);
   }
   //Self entry
   if (ch == 'Y') {
       cout << "Enter POWERBALL(between 1 to 26): ";
       cin >> playerBalls[5];
       while (playerBalls[5] < 1 || playerBalls[5]>26) {
           cout << "Enter POWERBALL(between 1 to 26): ";
           cin >> playerBalls[5];
       }
   }
   //Otherwise
   else {
       playerBalls[5]= getArandNum(1, 26);
   }
   cout << endl;
   //Sort both white arrays
   sortArray(winBalls,5);
   sortArray(playerBalls,5);
   //Get white ball match count
   int matchCnt = compareArrays(winBalls, playerBalls,5);
   //Red ball matching
   if (playerBalls[5] == winBalls[5]) {
       ch = 'Y';
   }
   else {
       ch = 'Y';
   }
   //Report generation
   cout << "\n**********Game Report**********\n" << endl;
   cout << fixed << setprecision(1) << "You win $" << getPoints(matchCnt, ch) << " for the game.\n" << endl;
   cout << "Here are your numbers:" << endl;
   displayArray(playerBalls, 6);
   cout << "\nHere are the winning numbers:" << endl;
   displayArray(winBalls, 6);
   cout << "\n**The last number is Power Ball number!!**\n" << endl;
   cout << "************************************\n" << endl;
   cout << "Thank you for using my program!!\nProgrammer:Your name\nsubject\nDue Date: " << endl;
}
//Function to display title and rule of the games
void titleRules() {
   cout << "Number Guessing Game" << endl;
   cout << "\nGame Rules:-" << endl;
   cout << "1. Select 5 numbers from 1 to 69 fro white balls.\n2. Select 1 number from 1 to 26 for red balls.\n"
       << "Price determined by how many of your numbers match the winning numbers.\n" << endl;
}
//Function return a random number with the given range in input arguments
int getArandNum(int min, int max) {
   return min + (rand() % (max - min + 1));
}
//Sort array using selection sort
void sortArray(int* arr, const int cnt) {
   for (int i = 0; i < cnt - 1; i++)
   {
       int min = i;
       for (int j = i + 1; j < cnt; j++) {
           if (arr[j] < arr[min]) {
               min = j;
           }
       }
       int temp = arr[min];
       arr[min] = arr[i];
       arr[i] = temp;      
   }
}
//Function to compare 2 arrays and return match count
int compareArrays(const int arr1[], const int arr2[], const int cnt) {
   int matchCnt = 0;
   for (int i = 0; i < cnt; i++) {
       if (arr1[i] == arr2[i]) {
           matchCnt++;
       }
   }
   return matchCnt;
}
//Function to display contenets of the array
void displayArray(const int arr[], const int cnt) {
   for (int i = 0; i < cnt; i++) {
       cout << arr[i] << " ";
   }
   cout << endl;
}
//Function to get points of the game
double getPoints(const int matchCnt, const char powerMatch) {
   if (matchCnt == 5 && powerMatch == 'Y') {
       return GRANDPRIZE;
   }
   else if (matchCnt == 5 && powerMatch == 'N') {
       return 1000000.00;
   }
   else if (matchCnt == 4 && powerMatch == 'Y') {
       return 50000.00;
   }
   else if (matchCnt == 4 && powerMatch == 'N') {
       return 100.00;
   }
   else if (matchCnt == 3 && powerMatch == 'Y') {
       return 100.00;
   }
   else if (matchCnt == 3 && powerMatch == 'N') {
       return 7.00;
   }
   else if (matchCnt == 2 && powerMatch == 'Y') {
       return 7.00;
   }
   else if (matchCnt == 1 && powerMatch == 'Y') {
       return 4.00;
   }
   else if (matchCnt == 1 && powerMatch == 'N') {
       return 4.00;
   }
   return 0.00;
}

------------------------------------------------------------------------

Output

Number Guessing Game

Game Rules:-
1. Select 5 numbers from 1 to 69 fro white balls.
2. Select 1 number from 1 to 26 for red balls.
Price determined by how many of your numbers match the winning numbers.

Do you want to self pick your white balls(Y or N): y
Enter a number 1(between 1 to 69): : 5
Enter a number 2(between 1 to 69): : 48
Enter a number 3(between 1 to 69): : 53
Enter a number 4(between 1 to 69): : 59
Enter a number 5(between 1 to 69): : 32
Do you want to self pick your red ball(Y or N): n


**********Game Report**********

You win $4.0 for the game.

Here are your numbers:
5 32 48 53 59 13

Here are the winning numbers:
5 42 45 56 57 21

**The last number is Power Ball number!!**

************************************

Thank you for using my program!!
Programmer:Your name
subject
Due Date:

Add a comment
Know the answer?
Add Answer to:
Please post screenshots only File Tools View CMSC 140 Common Projects Spring 2019(1) E - 3...
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...

  • 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...

  • ASSIGNMENT 5 – POWERBALL SIMULATION Powerball® is a combined large jackpot game and a cash game. ...

    ASSIGNMENT 5 – POWERBALL SIMULATION Powerball® is a combined large jackpot game and a cash game. Every Wednesday and Saturday night at 10:59 p.m. Eastern Time, we draw five white balls out of a drum with 69 balls (1-69) and one red ball out of a drum with 26 red balls (1-26). Draw sales cut off at least 59 minutes before the draw. Check for local cut-off time. Players win by matching one of the 9 Ways to Win. The...

  • 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...

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