Write an application that simulates a slot machine. The player starts out with M
ID: 3816810 • Letter: W
Question
Write an application that simulates a slot machine. The player starts out with M coins. The value of M is an input to the program, and you charge 25 cents per coin. For each play, the player can bet 1 to 4 coins. If the player enters 0 as the number of coins to bet, then the program stops playing. At the end of the game, the program displays the number of coins left and how much the player won or lost in the dollar amount. There are three slots on the machine, and each slot will display one of the three possible pieces: BELL, GRAPE, and CHERRY. When certain combinations appear on the slots, the machine will pay the player. The payoff combinations are these: The symbol ------ means any piece. If the player bets 4 coins and gets combination 5, for example, the machine pays the player 12 coins.Explanation / Answer
#include "stdafx.h" #include #include using namespace std; class slotMachine { private: int wheelA; int wheelB; int wheelC; double payOut; //amount of $ won during the current turn double moneyInMachine; //total amount of $ in the machine double gameCost; //the cost of one pull double moneyPaid; //the money put in by user public: //prototypes slotMachine(); bool displayMenu(void); bool pullHandle(void); void spinWheel(int &); double calculatePayout(); void insertCoin(double ); void displaySpinResults(); int Random(int, int); void displayTotals(); }; int main(void) { //create a slot machine object slotMachine mySlot; //Start the slot machine game //Keep running until the user //decides to quit bool ok = true; while (ok){ ok = mySlot.displayMenu(); }; return 0; } slotMachine::slotMachine () { //constructor, set the initial state //of all the properties srand((int) time(0)); moneyInMachine = 100; moneyPaid = 0; payOut = 0; wheelA = 0; wheelB = 0; wheelC = 0; gameCost = 1; } bool slotMachine::displayMenu(void){ //main menu, executes the command selected by the //user or returns a value to terminate game execution char choice = 'Z'; bool continueGame = true; cout > choice; switch (choice) { case 'e': case 'E': //stop game continueGame = false; break; case 'a': case 'A': //pay double money; cout money; insertCoin(money); break; case 'p': case 'P': //pull if (pullHandle()){ coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.