#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
usingnamespace std;
int bank = 100;
int bet;
int card1;
int card2;
int card3;
int dealer;
int hand;
char hit;
char play;
char quit;
srand((unsigned)time(NULL));
int main()
{
cout << "Welcome to Blackjack \n";
cout << "Press y to play or n to quit \n";
cin >> play;
}
int begin()
{
if (play == 'y'){
cout << "You will start with $100 in the bank \n";
}
if (play == 'n'){
return 0;
}
}
int placebet()
{
while (play == 'y')
{
cout << "You currently have $ "<< bank <<" \n";
cout << "Enter your bet \n";
cin >> bet;
if (bank == 0){
cout << "You are out of money game over \n";
return main();}
if (bet > bank){
cout << "You do not have enough money \n";
return placebet();}
cout << "Your bet is $ "<< bet <<" \n";
bank = bank - bet
cout<< "You have $ "<< bank <<" left in your bank \n";
}
}
}
char deal()
{
card1 = rand()%13+1;
card2 = rand()%13+1;
cout << "Your first two cards are "<< card1 <<" and "<< card2 <<" \n";
hand = card1 + card2;
if (hand > 21){
cout << "BUST \n";
return placebet();
}
else
cout << "Your total is "<< hand <<", enter y to hit or n to stay \n";
cin >> hit;
while (hit == 'y'){
card3 = rand()%13+1;
cout << "Your third card is "<< card3 <<" \n";
hand = card3 + hand;
if (hand > 21){
cout << "BUST \n";
return placebet()
else
cout << "Your total is "<< hand <<", enter y to hit or n to stay \n";
cin >> hit;
}
dealer = 15+rand()%6;
cout << "The dealer has a total of "<< dealer <<" \n";
{
char decision()
{
if (dealer > hand){
cout << "You have lost this hand \m";
cout << "You have a total of $ "<< bank <<" in the bank \n";
}
if (dealer == hand){
cout << "You have lost this hand \n";
cout << "You have a total of $ "<< bank <<" in the bank \n";
}
if (hand > dealer){
cout << "You have won this hand \n";
bank = bank + 1.5 * bet;
cout << "You have have a total of $ "<< bank <<" in the bank \n";
}
cout << "Enter y to play another hand, or n to quit \n";
cin >> quit;
if (quit == 'n'){
return 0;}
}