Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students explore these related Databases questions