Question: Game of Craps C++ #include using namespace std; void roll (int *); // using pointer to catch the random variable value of two dicerolls at

Game of Craps C++

#include

using namespace std; void roll (int *); // using pointer to catch the random variable value of two dicerolls at one time .

//these global variable with static variable win use to operate the working of code . //static win, account because two times input given by user to add the diceroll with win number and //account (means balance of user) .

static int account = 100; static int win = 0; int bet = 0;

int main () { char c; int diceroll1, diceroll2; cout << "Welcome to the CRAPS game. "; while(1){ cout << "You have $"< cin >> c; if (c == 'y') { cout << "How much do you want to bet? "; cin >> bet; diceroll1 = rand () % 6 + 1; diceroll2 = rand () % 6 + 1; // rand()%6+1 get the value between 6 to 1 and also included 6 or 1 both . roll (&diceroll1); // send the address of diceroll values . roll (&diceroll2); if (win == 7) { cout << "You rolled a " << diceroll1 << " and a " << diceroll2 << ". Your total is 7. You win! "; account+=bet; cout<<"You have $"< } else if (win == 11) { cout << "You rolled a " << diceroll1 << " and a " << diceroll2 << ". Your total is 11. You win! "; account+=bet; cout<<"You have $"< } else if(win==2 ||win==3 ||win==12){ cout<<"You lose! "; } } else if(c=='n'){ cout<<"Thank you for playing."; break; } } return 0; }

void roll (int *a) { win = win + *a; }

Modify the craps program to keep track of your bank. After each hand, you have Do you want to roll again (y/n/s). If you select s you can save your amount of money. The game then repeats the question so you can continue or press n to quit. When you first start the program it asks, Do you want to load a previous session? If you say y, your bank is updated to the amount it was when it was saved. If you say n, the game proceeds as before. If there was no previous session, obviously the program wont be able to find your save file, and should give an appropriate message like, Sorry, no save file exists on this computer.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!