CASINO GAME CONFUSION do while
Apr 8, 2015 at 12:53am UTC
HEY EVEYONE!I need some help with this code!
It is a craps game and a casino menu
the rules for the game go
on the first roll if you roll 7 or 11 user wins bet and must ask the user to play again or go back to the menu
if a 2 3 or 12 is rolled on the first roll, user loses bet and must ask the user to play again or go back to the menu
if a 4 5 6 8 9 10 are rolled then you must ask the user to roll again
on the second roll if the user rolls the same number user wins bet
on the second roll if user rolls 7 user loses bet
I dont understand how to break the do while loop here to roll again for the second roll and how to get the code to roll again if the user wins or loses on the first round
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
/*
*
*/
int rollDie(int rand_number) {
srand(time(0));
rand_number = (rand() % 6) + 1;
return rand_number;
}
int main(int argc, char ** argv) {
int choice;
int chips;
string name;
chips = 100;
int bet;
int sum1;
int sum2;
cout << "Hello! Please enter your name. " << endl;
cin >> name;
do {
cout << "Hello, " << name << ", you have " << chips << " chips to play." ;
cout << endl;
cout << "What game do you want to play?" << endl;
cout << "1. 5 Card Poker" << endl;
cout << "2. Craps" << endl;
cout << "3. Leave the table!" ;
cout << endl;
cin >> choice;
if (choice == 3) {
cout << "Thanks for playing." ;
} else if (choice < 1 || choice > 2) {
cout << "Please enter a correct choice!" ;
continue ;
}
switch (choice) {
case 1:
cout << "Welcome to 5 Card Poker, " << name << "!" << endl;
cout << "Are you ready to play?" << endl;
cout << "y or n : " ;
string response;
cin >> response;
if (response == "n" ) {
continue ;
}
if (response == "y" ) {
continue ;
}
}
switch (choice) {
case 2:
cout << "Welcome to Craps, " << name << "!" << endl;
cout << "Are you ready to play?" << endl;
cout << "y or n : " ;
string response;
cin >> response;
if (response == "y" ) {
srand(time(NULL));
cout << "How many chips would you like to bet "
"this round? " ;
cin >> bet;
sum1 = rollDie(6) + rollDie(6);
while (chips < bet) {
cout << "Sorry " << name << ", but you cannot bet more "
"than you have!" << endl;
cout << "Enter your bet: " ;
cin >> bet;
}
cout << "Your first roll was: " << sum1 << endl;
do {
if (sum1 == 7 || sum1 == 11) {
chips = chips + bet;
cout << "Congratulations you won " << bet
<< " chips." << endl;
cout << "You now have " << chips
<< " chips." << endl;
cout << "Would you like to play again?" << endl
<< "Please enter 1 to play again."
<< endl
<< "Please enter 2 to go back to the "
"menu." ;
cin >> choice;
}
else if (sum1 == 2 || sum1 == 3 || sum1 == 12) {
cout << "Sorry, you lost." << endl;
chips = chips - bet;
cout << "You now have " << chips << " chips."
<< endl;
cout << "Please enter 1 to play again." << endl;
cout << "Please enter 2 to go back to the menu"
<< endl;
cin >> choice;
} else if (sum1 == 4 || sum1 == 5 || sum1 == 8 || sum1 == 9 || sum1 == 10) {
cout << "On to the next round!" << endl;
cout << "Please enter 2 to roll for the next round!" << endl;
cin >> choice;
}
} while (choice == 1);
int sum2;
sum2 = rollDie(6) + rollDie(6);
while (chips < bet) {
cout << "Sorry " << name << ", but you cannot bet more "
"than you have!" << endl;
cout << "Enter your bet: " ;
cin >> bet;
}
cout << "Your second roll was: " << sum2 << endl;
if (sum1 == sum2) {
chips = chips + bet;
cout << "Congratulations you won " << bet
<< " chips." << endl;
cout << "You now have " << chips << " chips"
<< endl;
cout << "Please enter 1 to play again."
<< endl
<< "Please enter 2 to go back to the "
"menu." << endl;
cin >> choice;
} else if (sum2 == 7) {
cout << "Sorry, you lost." << endl;
chips = chips - bet;
cout << "You now have " << chips << " chips."
<< endl;
cout << "Please enter 1 to play again." << endl
<< "Please enter 2 to go back to the "
"menu." << endl;
cin >> choice;
} else if (sum1 == 4 || sum1 == 5 || sum1 == 8 || sum1 == 9 || sum1 == 10
|| sum1 == 2 || sum1 == 3 || sum1 == 12 || sum1 == 6) {
cout << "Press 1 to roll again" << endl;
cin >> choice;
}
}
}
} while (choice != 3);
return 0;
}
Topic archived. No new replies allowed.