# [C++] Casino Game

```#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void roulette();
void blackjack();
void dice();

int main()
{
int age;
cout << "Welcome to the Casino!" << endl; // Welcomes User
cout << "Please enter your age: " << endl; // Asks for Age
cin >> age; // Age Input
if (age < 21) // If less than 21, you cannot play.
{
cout << "Sorry, you are not old enough to gamble." << endl;
return 0;
}
else if (age > 21) // If 21 or older, you can play.
{
int gameChoice; // Initalize gameChoice
cout << "Thanks! What game would you like to play?" << endl; // Game Options
cout << "1. Roulette" << endl;
cout << "2. Blackjack" << endl;
cout << "3. 7-11-Doubles" << endl;
cin >> gameChoice; // Game Option Input
if (gameChoice == 1) // Choice 1
{
roulette();
}
else if (gameChoice == 2) // Choice 2
{
blackjack();
}
else if (gameChoice == 3) // Choice 3
{
dice();
}
}
return 0;
}

void roulette()
{
double winnings; // Winnings Calculator
int randomNumber; // The Board
int x = 2, y = 1; // Odds and Events
int betChoice; // Bet on Colors or Numbers?
double betAmount; // How much to bet?
cout << "How much would you like to bet?" << endl;
cin >> betAmount;
cout << "Do you want to bet on colors or numbers?" << endl;
cout << "1. Colors" << endl;
cout << "2. Numbers" << endl;
cin >> betChoice;
srand(time(0)); // Random Number Generator
randomNumber = rand() % 36;
if (betChoice == 1)
{
int betColor;
cout << "What color would you like to bet on?" << endl;
cout << "1. Black (Evens)" << endl;
cout << "2. Red (Odds)" << endl;
cout << "3. Green (0)" << endl;
cin >> betColor;
if (betColor == 1) // Black (evens)
{
while (x < 36)
{
if (x == randomNumber)
{
cout << "You landed on Black! Your number was " << randomNumber << "." << endl;
winnings = betAmount * 2;
cout << "You're the lucky winner! You won \$" << winnings << " USD." << endl;
}
x = x + 2;
}
}
else if (betColor == 2) // Red (odds)
{
while (y < 36)
{
if (y == randomNumber)
{
cout << "You landed on Red! Your number was " << randomNumber << "." << endl;
winnings = betAmount * 2;
cout << "You're today's lucky winner! You won \$" << winnings << " USD." << endl;
}
y = y + 2;
}
}
else if (betColor == 3) // Green (0)
{
if (randomNumber == 0)
{
cout << "You landed on Green! Your number was " << randomNumber << "." << endl;
winnings = betAmount * 2;
cout << "You're the lucky winner for today! You won \$" << winnings << " USD." << endl;
}
}
}
else if (betChoice == 2) // Numbers
{
int betNumber;
cout << "Please guess a number between 0 and 36: " << endl; // Please Guess Question
cin >> betNumber;
while (betNumber < 0 || betNumber > 36) // Keeps within 0 to 36 Range
{
cout << "Sorry, please choose a number between 0 and 36." << endl;
cin >> betNumber;
}
if (betNumber == randomNumber)
{
cout << "You landed on " << randomNumber << "." << endl;
winnings = betAmount * 35;
cout << "Congratulations! You are the lucky winner! You won " << winnings << " USD." << endl;
}
else if (betNumber != randomNumber)
{
cout << "You landed on " << randomNumber << "." << endl;
cout << "Sorry! You lost. :(" << endl;
}
}
}

void blackjack()
{
double winnings; // Winnings Calculator
int choice; // Player Choice
int randomCard; // The Cards
int playerSum = 0, dealerSum = 0; // Player & Dealer
double betAmount; // Bet Amount
cout << "How much would you like to bet?" << endl;
cin >> betAmount;
randomCard =  1 + rand() % 11; // Random Number Generator for Player
playerSum = playerSum + randomCard; // Calculate Card
randomCard = 1 + rand() % 11; // Random Number Generator for Player
playerSum = playerSum + randomCard; // Calculate Card
cout << "The Player's Hand: " << playerSum << endl;
randomCard = 1 + rand() % 11; // Random Number Generator for Dealer
dealerSum = dealerSum + randomCard; // Calculate Card
randomCard = 1 + rand() % 11; // Random Number Generator for Dealer
dealerSum = dealerSum + randomCard; // Calculate Card
cout << "The Dealer's Hand: " << dealerSum << endl;
winnings = betAmount * 2; // Winnings Multipler
if (playerSum == 21)
{
cout << "You beat the dealer and have 21! You win: \$" << winnings << endl;
}
else if (dealerSum == 21)
{
cout << "You lost to the dealer and they have 21. :(" << endl;
}
else
{
while (playerSum < 21)
{
if (dealerSum <= 17)
{
cout << "Dealer Hits" << endl;
randomCard = 1 + rand() % 11;
dealerSum = dealerSum + randomCard;
cout << "The Dealer's Hand: " << dealerSum << endl;
if (dealerSum > 21)
{
cout << "You beat the dealer. They exceeded 21." << endl;
}
}
else if (dealerSum >= 17)
{
cout << "The Dealer Stays" << endl;
}
else if (dealerSum < 21)
{
cout << "The Dealer Stays" << endl;
}
cout << "What would you like to do?" << endl; // Option
cout << "1. Hit" << endl; // Hit
cout << "2. Stay" << endl; // Stay
cin >> choice;
if (choice == 1) // Option 1 - Hit
{
randomCard = 1 + rand() % 12; // Random Number Generator
playerSum = playerSum + randomCard; // Calculate Cards
cout << "The Player's Hand: " << playerSum << endl;
if (playerSum > 21)
{
cout << "You lost to the dealer. You exceeded 21." << endl;
}
}
else if (choice == 2) // Option 2 - Stay
{
if (dealerSum < playerSum)
{
cout << "You beat the dealer and won! You win: \$" << winnings << endl;
}
else if (dealerSum > playerSum)
{
cout << "The Dealer Wins! You lost :(" << endl;
}
}
}
}
}

void dice()
{
double winnings; // Winnings Calculator
int randomNumber1, randomNumber2; // Dice 1 and Dice 2
double betAmount; // Bet Amount
cout << "How much would you like to bet?" << endl;
cin >> betAmount;
randomNumber1 = rand() % 6 + 1; // Dice 1
randomNumber2 = rand() % 6 + 1; // Dice 2
cout << "Your first dice was a " << randomNumber1 << "." << endl;
cout << "Your second dice was a " << randomNumber2 << "." << endl;
if(randomNumber1 + randomNumber2 == 7) // If 7, win!
{
cout << "Congrautlations! You won!" << endl;
winnings = betAmount * 2;
cout << "You won: " << winnings << " USD" << endl;
}
else if (randomNumber1 + randomNumber2 == 11) // If 11, win!
{
cout << "Congrautlations! You won!" << endl;
winnings = betAmount * 2;
cout << "You won: " << winnings << " USD" << endl;
}
else if (randomNumber1 == randomNumber2) // If Dice 1 = Dice 2, win!
{
cout << "Congrautlations! You won!" << endl;
winnings = betAmount * 2;
cout << "You won: " << winnings << " USD" << endl;
}
else if (randomNumber1 != randomNumber2) // Anything else, lose :(
{
cout << "Sorry! You lost :(" << endl;
}
}```