0% found this document useful (0 votes)
24 views

Wrong!!

The document defines functions for rolling dice in a craps game. An OpeningRoll function takes the opening roll and determines if the player wins, loses, or a point is established. If a point is set, a do-while loop continues rolling until either a 7 or the point value is rolled, at which point the player wins or loses respectively.

Uploaded by

ukhyeon
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Wrong!!

The document defines functions for rolling dice in a craps game. An OpeningRoll function takes the opening roll and determines if the player wins, loses, or a point is established. If a point is set, a do-while loop continues rolling until either a 7 or the point value is rolled, at which point the player wins or loses respectively.

Uploaded by

ukhyeon
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream> #include <iomanip> using namespace std; int RollOneDie(); int ThrowDice(); bool OpeningRoll(int& ); bool OpeningRoll

(int & point) { point = ThrowDice(); if ((point==7)||(point==11)) { cout <<"Player wins!"; point = -1; return true; } else if((point==2)||(point==3)||(point==12)) { cout << "Player loses!"; point = -1; return true; } else { cout << "Point value is " << point <<endl; return false; a = ThrowDice(); }while (!((a==7)||(a==point))); if (a==7) cout << "Player loses!"; else cout << "Player wins!"; } return 0; } } }

int main() { int point=0; bool End = OpeningRoll(point); if ( End ) { return 0; } else { int a; do{

int RollOneDie() { int random; cout << "Please enter an integer in the range of 1 to 6\n"; cin >> random; return random; } int ThrowDice() { int x,y,z; x= RollOneDie(); y= RollOneDie(); z= x + y; cout << "Player roll "<< x << "+" << y << "=" << z << endl; return z; }

WRONG!!
#include <iostream> #include <iomanip> using namespace std; int RollOneDie(); int ThrowDice(); bool OpeningRoll(int& );

int main() { int point=0, sum; if ( OpeningRoll(point))

{ return 0; } else { int a; do{ a = ThrowDice(); }while (!((a==7)||(a==sum))); if (a==7) cout << "Player loses!"; else cout << "Player wins!"; } return 0; } bool OpeningRoll (int & point) { int sum = ThrowDice(); if ((sum==7)||(sum==11)) { cout <<"Player wins!"; point = -1; return true; } else if ((sum==2)||(sum==3)||(sum==12)) { cout << "Player loses!"; point = -1; return true; } else { cout << "Point value is " << sum int RollOneDie() { int random; cout << "Please enter an integer in the range of 1 to 6\n"; cin >> random; return random; } <<endl; return false; } }

int ThrowDice() { int x,y,z; x= RollOneDie(); y= RollOneDie(); z= x + y; cout << "Player roll "<< x << "+" << y << "=" << z << endl; return z; }

You might also like