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
|
#include <iostream>
using namespace std;
void craps()
{
srand(time(0));
cout << "Welcome to Craps! \n";
cout << "Craps is a game that takes place over two rounds. "
"In round one, two dice are rolled. If the sum of "
"the dice is either 7 or 11, you win your bet "
"(known as the line bet). If it’s 2,3 or 12, you "
" lose, otherwise known as craps. If it is any "
"other number, the next round begins.\n";
cout << "In round 2, two dice are rolled. If the roll is 7, "
"all bets are lost. Otherwise, the rolls continue "
"until the first number rolled is rolled again, "
"winning the bet, and starting at round 1 again.\n";
int gamesPlayed = 0;
int betAmount;
int chips = 100;
cout << "You will start off with 100 chips.\n";
cout << "If you would care to place a wager (if no wager enter a 0) "
"enter it here: ";
cin >> betAmount;
int chipsLeft;
char input;
int won = 0;
int loss = 0;
for(int i = 0; i < 2; i++)
{
int firstDie1 = rand() % 6 + 1;
int firstDie2 = rand() % 6 + 1;
int roll = firstDie1 + firstDie2;
cout << "Your first roll is " << roll << endl;
if(roll == 7 || roll == 11)
{
cout << "You won! ";
gamesPlayed++;
won++;
chipsLeft = chips + betAmount;
}
else if (roll == 2 || roll == 3 || roll == 12)
{
cout << "You lose ";
gamesPlayed++;
chipsLeft = chips - betAmount;
loss++;
}
else
{
cout << "Next round! ";
do{
int secondDie1 = rand() % 6 + 1;
int secondDie2 = rand() % 6 + 1;
int rollTwo = secondDie1 + secondDie2;
cout << "Your next roll is " << rollTwo << endl;
if(rollTwo == 7)
{
cout << "You lose";
gamesPlayed++;
chipsLeft = chips - betAmount;
loss++;
}
else if(rollTwo == roll)
{
cout << "You win!";
gamesPlayed++;
chipsLeft = chips + betAmount;
won++;
}
cout << "Would you like to play again? Enter Y for yes";
cin >> input;
}while(input = 'Y');
}
}
cout << "Thank you for playing!\n";
}
void poker()
{
cout << "Welcome to poker! Would you like to play?";
string input;
cin >> input;
cout << "Thank you for playing!\n";
}
int main(int argc, char** argv) {
int choice;
int chips = 100;
int chipsLeft;
do{
cout << "---------------------------Main Menu---------------------------\n";
cout << "-----------Choose which game you would like to play!-----------\n";
cout << "------You have currently " << chipsLeft << " chips left.-------\n";
cout << "---------------------------1) Craps!---------------------------\n";
cout << "---------------------------2) Poker!---------------------------\n";
cout << "---------------------------3) Quit-----------------------------\n";
cin >> choice;
switch(choice)
{
case 1:
craps();
break;
case 2:
poker();
break;
case 3:
cout << "Thanks for playing!";
default:
cout << "Not a valid input";
}
}while(choice != 3);
return 0;
}
|