Question

In: Computer Science

Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for...

Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for this game are special oriental dice. Each die has six different patterns. The six possible patterns are: Fish, Shrimp, Crab, Chicken, goldenCoin, Barrel. This game has three dice. In this game, the player can place his or her bet on any die-pattern. The amount of the winning prize is directly proportional to the number of matched dice after the two dice have been tossed for each game. Rules of this game:  Initial cash for this game is specified by player.  Maximum bet for each game is $1000.  Minimum bet for each game is $30.  Three dice are used per game.  Player can place his or her bet on any one of those six face-patterns of the die for each game.  The winning prize is based on how many matched dice have been found:  If two matched dice have been found, then the prize is 2x.  If three matched dice have been found, then the prize is 6x.  If no matched die has been found, then the player loses his or her bet for this game-session.

Solutions

Expert Solution

// C++ program to simulate Million dollar Game

#include <iostream>

#include <cstdlib>

#include <ctime>

#include <iomanip>

using namespace std;

enum diePattern

{

       Fish,

       Shrimp,

       Crab,

       Chicken,

       GoldenCoin,

       Barrel

};

class Die

{

private:

       diePattern dieValue;

public:

       Die();

       void Shake();

       diePattern Get();

};

// constructor

Die::Die()

{

       dieValue = Fish;

}

// function to roll a die

void Die::Shake()

{

       int num = rand()%6;

       switch(num)

       {

       case 0:

             dieValue = Fish;

             break;

       case 1:

             dieValue = Shrimp;

             break;

       case 2:

             dieValue = Crab;

             break;

       case 3:

             dieValue = Chicken;

             break;

       case 4:

             dieValue = GoldenCoin;

             break;

       case 5:

             dieValue = Barrel;

             break;

       }

}

// function to return the die value

diePattern Die::Get()

{

       return dieValue;

}

// function declaration

void show_help();

void show_diePattern(diePattern die);

double check_win_or_lose(Die dice[3],double bet_amount);

int main() {

    srand(time(NULL));

       int choice, total_games=0, total_win=0;

       double total_amount, bet_amount=0, amount_won;

       Die dice[3];

    // loop that continues till the user exits

       do

       {

             cout<<"\n\t\t Million Dollar Game"<<endl;

             cout<<"\t\t========================"<<endl;

             cout<<"0. Help (display rules of the game)"<<endl;

             cout<<"1. Enter the total amount of money you bring to the casino for gambling"<<endl;

             cout<<"2. Roll the dice and then place your bet here (Max. is $1000 and Min. is $30)"<<endl;

             cout<<"3. Check win or lose for this round only"<<endl;

             cout<<"4. Display your gambling results"<<endl<<"\t o current cash on hand"<<endl<<"\t o Percentage of winnings"<<endl<<"\t o total number of games played so far"<<endl;

             cout<<"9. Quit"<<endl;

             cout<<"Enter your choice : ";

             cin>>choice;

             switch(choice)

             {

             case 0: // display help

                    show_help();

                    break;

             case 1:

            // input of total amount of money

                    cout<<"Enter the total amount of money : $";

                    cin>>total_amount;

                    while(total_amount <= 0)

            {

                cout<<"Invalid amount. Amount must be greater than 0"<<endl;

                cout<<"Enter the total amount of money : $";

                cin>>total_amount;

            }

                    break;

             case 2: // place a bet on a pattern

                    dice[0].Shake();

                    cout<<"\nDice 1 : ";

                    show_diePattern(dice[0].Get());

                    cout<<"Enter the bet amount : $";

                    cin>>bet_amount;

                    // validate bet amount

                    while(bet_amount < 30 || bet_amount > 1000)

                    {

                           cout<<"Invalid bet amount. Bet amount must be between 30-1000 (inclusive)"<<endl;

                           cout<<"Enter the bet amount : $";

                           cin>>bet_amount;

                    }

                    // check if user has sufficient amount

                    if(bet_amount <= total_amount)

                total_amount -= bet_amount;

            else

                cout<<"Insufficient amount left"<<endl;

                    break;

             case 3:

                 // if user has places the bet, check user won or lost

                    if(bet_amount > 0)

                    {

                           amount_won = check_win_or_lose(dice,bet_amount);

                           total_games++;

                           if(amount_won > 0)

                           {

                               total_win++;

                               cout<<"You won $"<<amount_won<<endl;

                           }else

                    cout<<"You lose $"<<bet_amount<<endl;

                           total_amount += amount_won;

                           bet_amount = 0;

                    }else

                           cout<<"Place bet on a pattern first"<<endl;

                    break;

             case 4:

                 // output the results

                    cout<<"Gambling Results : "<<endl;

                    cout<<"Current cash on hand : $"<<total_amount<<endl;

                    cout<<"Percentage of winnings : "<<fixed<<setprecision(2)<<(((float)(total_win*100))/total_games)<<endl;

                    cout<<"Total number of games played so far : "<<total_games<<endl;

                    break;

             case 9:

                    cout<<"Thank you for playing the game"<<endl;

                    break;

             }

       }while(choice != 9);

       return 0;

}

// function to display rules of the game

void show_help()

{

       cout<<"\t\tRules of the game"<<endl;

       cout<<"Initial cash for this game is specified by the player"<<endl;

       cout<<"Maximum bet for each game is $1000"<<endl;

       cout<<"Minimum bet for each game is $30"<<endl;

       cout<<"Three dice are used per game"<<endl;

       cout<<"Player can place his/her bet on any one of those six face-pattern of the die for each game"<<endl;

       cout<<"The winning prize is based on how many matched dice have been found : "<<endl;

       cout<<"\tIf two matched dice have been found then the prize is 2x"<<endl;

       cout<<"\tIf three matched dice have been found then the prize is 6x"<<endl;

       cout<<"\tIf no matched dice has been found then the player loses his or her bet for this game session"<<endl;

}

// function to display the pattern on the die

void show_diePattern(diePattern die)

{

       switch(die)

       {

       case Fish:

             cout<<"Fish";

             break;

       case Shrimp:

             cout<<"Shrimp";

             break;

       case Crab:

             cout<<"Crab";

             break;

       case Chicken:

             cout<<"Chicken";

             break;

       case GoldenCoin:

             cout<<"GoldenCoin";

             break;

       case Barrel:

             cout<<"Barrel";

             break;

       }

       cout<<endl;

}

// function to return the amount won by the user

double check_win_or_lose(Die dice[3],double bet_amount)

{

       for(int i=1;i<3;i++)

       {

             dice[i].Shake();

       }

       cout<<"Dice 2 : ";

       show_diePattern(dice[1].Get());

       cout<<"Dice 3 : ";

       show_diePattern(dice[2].Get());

       if((dice[0].Get() == dice[1].Get()) && (dice[0].Get() == dice[2].Get()))

             return 6*bet_amount;

       else if((dice[0].Get() == dice[1].Get()) || (dice[0].Get() == dice[2].Get()))

             return 2*bet_amount;

       else

             return 0;

}

//end of program

Output:


Related Solutions

Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
1. Write a program that plays a simple dice game between the computer and the user....
1. Write a program that plays a simple dice game between the computer and the user. When the program runs, it asks the user to input an even number in the interval [2..12], the number of plays. Display a prompt and read the input into a variable called ‘plays’ using input validation. Your code must ensure that the input always ends up being valid, i.e. even and in [2..12]. 2. A loop then repeats for ‘plays’ iterations. Do the following...
C++ ^ ^ Write a menu driven program to perform following operations using a map container...
C++ ^ ^ Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input is provided,...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program that displays the following menu: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a rectangle 3. Calculate the area of a triangle 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for the radius of the circle and then display the area. Use the following formula to calculate the circle’s area: ?...
Write a menu-driven program to handle the flow of widgets into and out of a warehouse....
Write a menu-driven program to handle the flow of widgets into and out of a warehouse.     The warehouse will have numerous deliveries of new widgets and orders for widgets     The widgets in a filled order are billed at a profit of 50 percent over their cost     Each delivery of new widgets may have a different cost associated with it     The accountants for the firm have instituted a last-in, first-out system for filling orders         the newest...
Write a menu-driven program to test the three functions conver_tlength(), convert_width(), convert_volume() in a program. Program...
Write a menu-driven program to test the three functions conver_tlength(), convert_width(), convert_volume() in a program. Program should allow the user to select one of the options according to whether lengths, weights or volume are to be converted, read the volue to be converted and the units, and then call the appropriate function to carry out the conversion In unit out unit I C (inch to centimeter 1 in = 2.4 cm) F C (feet to centimeter 1 ft = 30.4...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java program that will solve the following problem. The program uses one and two-dimensional arrays to accomplish the tasks specified below. The menu is shown below. Please build a control panel as follows: (Note: the first letter is shown as bold for emphasis and you do not have to make them bold in your program.) Help SetParams FillArray DisplayResults Quit Upon program execution, the screen...
Write a code for simple racing game (using dots) on c program.
Write a code for simple racing game (using dots) on c program.
Create a simple dice game in Java. Add screenshots and the program here.
Create a simple dice game in Java. Add screenshots and the program here.
Write a menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT