Craps
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 | #include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int diceRoll();
int pointRoll();
int roll, point, number, cash;
int win, loss, bet, dice1, dice2;
char ans;
int diceRoll() {
dice1=(rand()%6);
dice2=(rand()%6);
number=(dice1 + dice2 + 2);
return number;
}
int pointRoll() {
while (true) {
int value = diceRoll();
if (value == 7) {
cout << "You rolled 7 and LOST!\n";
cash = cash - bet;
cout << "You now have $" << loss << "\n";
break;
}
else if(point == value) {
cout << "You rolled " << point << " and WON!\n";
cash = cash + (bet*2);
cout << "You now have $" << cash << "\n";
break;
}
else {
cout << "You rolled " << value << ", roll again.\n";
}
}
return 0;
}
int main() {
cout << "How much you got foo: ";
cin >> cash;
do {
cout << "How much you bettin sucka: ";
cin >> bet;
srand(time(NULL));
roll = diceRoll();
if ((roll ==7 ) || (roll == 11)) {
cout << "You rolled " << roll << " and WON!\n";
cash = cash + (bet*2);
cout << "You now have $" << cash << "\n";
bet = 0;
}
else if ((roll == 2) || (roll == 3) || (roll == 12)) {
cout << "You rolled " << roll << " and LOST!\n";
cash = cash - bet;
cout << "You now have $" << cash << "\n";
bet = 0;
}
else {
cout << "Point: " << roll << endl;
point = roll;
pointRoll();
if (cash <= 0) {
cout << "You're a bum and you don't have enough money to play.\n";
break;
}
}
cout << "Would you like to play again (y/n): ";
cin >> ans;
}
while (ans=='y' || ans=='Y');
system("pause");
return 0;
}
|