Write and compile a C++ program to simulate a slot machine. A slot machine holds
ID: 3652848 • Letter: W
Question
Write and compile a C++ program to simulate a slot machine. A slot machine holds a number of coins, a private field, that a player can win. Each time a player puts a coin into the machine, they have a 70% chance of winning. To simulate this probability of winning, generate a random number between 1 and 10 (rand() % 10 + 1). If this number is between 1 and 7 (inclusive), then the player wins, otherwise they lose. In any case, it costs them 1 coin to play, which is added to the slot machine's number of coins. Assume that the player has an unlimited number of coins. The user repeatedly plays until they have won all of the coins in the machine, at which point the simulation ends. Thus, the main program should repeat until the slot machine contains no more coins. As an added note, the main function must also initialize the random number generator (srand(time(NULL)) where time(...) is in the file). A sketch of a possible interface of the slot machine class is given as follows, that is public: constructor (initialize a slot machine with 12 coins) coins function (get the number of coins remaining in the slot machine) play function (user inserts a coin and a random number is drawn, with the user either winning or losing a coin) private: add a coin (increment number of coins in slot machine) draw a random number (draw a random number between 1 and 10) pay out a coin (decrement number of coins in slot machine) Feel free to add any functions to this class that you think you need.Explanation / Answer
#include #include int main() { char slot1[6] = {'c','c','b','p','p','p'}; char slot2[5] = {'c','b','b','b','p'}; char slot3[5] = {'c','b','p','p','o'}; int e = 6; int f = 5; int g = 5; int temp; temp=rand()%e; temp=rand()%f; temp=rand()%g; printf ("A:%d,B:%d,C:%d ",slot1,slot2,slot3); return 0; }Related 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.