1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
#include <iostream>
#include <cstdlib>
using namespace std;
int dice();
int game();
int money(int, int);
bool outcome;
int bet;
int saved;
int main(){
char decision;
int saved = 10000;
outcome = false;
cout << "Hello and welcome to the Craps table. You have $" << saved << endl;
cout << "Would you like to test your luck? [Y/N]" << endl;
cin >> decision;
switch (decision){
case 'Y': case 'y':
cout << "May lady luck's fortune be ever in your favor!\n";
money( bet,saved);
break;
case 'N': case 'n':
cout << "Was a pleasure playing with you. Hope you come back soon!\n";
return 0;
break;
default:
cout << "Oh, come on now. Seriously now, want to play or not?\n";
cin.clear();
main();
break;
}
return 0;
}
int dice(){
int die1 = (1 + rand() % 6);
int die2 = (1 + rand() % 6);
int total = die1 + die2;
cout << "You rolled a " << die1 << " and a " << die2 << " which in total is " << total << endl;
return total;
}
int money(int bet, int saved){
char play = 0;
cout << "You have $" << saved << endl;
cout << "How much would you like to bet?\n";
cin >> bet;
if (bet > saved){
cout << "Sorry, appears you don't have that much money. How about a smaller amount?" << endl;
cin.clear();
money(bet, saved);
}
game();
if (outcome == true){
saved = +(bet * 2);
cout << "You now have $" << saved << endl;
cout << "Would you like to keep playing? [Y/N]" << endl;
cin >> play;
switch (play){
case'y':
money(bet, saved);
break;
case 'Y':
money(bet, saved);
break;
case'n':
cout << "Was a pleasure playing with you. Hope you come back soon!\n";
return 0;
case'N':
cout << "Was a pleasure playing with you. Hope you come back soon!\n";
return 0;
default:
cout << "Oh, come on now. Seriously now, want to play or not?\n";
cin >> play;
break;
}
}
else{
if (outcome == false){
saved -=bet;
cout << "You still have $" << saved << endl;
cout << "Would you like to keep playing? [Y/N]" << endl;
cin >> play;
switch (play){
case'y': case 'Y':
game();
break;
case'n': case'N':
cout << "Was a pleasure playing with you. Hope you come back soon!\n";
return 0;
default:
cout << "Oh, come on now. Seriously now, want to play or not?\n";
cin >> play;
break;
}
}
}
}
int game(){
int froll = 0, roll = 0, point = 0;
bool outcome = false;
froll = dice();
if (froll == 7 || froll == 11){
cout << "Congratulations! You win!" << endl;
outcome = true;
}
else if (froll == 2 || froll == 3 || froll == 12){
cout << "So sorry, better luck next time" << endl;
outcome = false;
}
else{
point = froll;
cout << "Point is " << point << endl;
while (outcome == false){
roll = dice();
if (roll == point){
cout << "Congratulations! You win!" << endl;
outcome = true;
}
else if (roll == 7){
cout << "So sorry, better luck next time" << endl;
outcome = false;
}
}
}
return outcome;
money(bet, saved);
}
|