I am wanting to provide the player of my game with an option to play the game again.
This is what I currently have:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
int main()
{
srand((unsigned)time(0));
int dealer_card1 = rand() % 13+1;
int dealer_card2 = rand() % 13+1;
int player_card1 = rand() % 13+1;
int player_card2 = rand() % 13+1;
char ans = 'n';
cout << "Welcome to your game of Blackjack!\n";
cout << "\n" << "the dealer has ";
switch (dealer_card1){
case 1: cout << "Ace and ";
break;
case 11: cout << "Jack and ";
break;
case 12: cout << "Queen and ";
break;
case 13: cout << "King and ";
default: cout << dealer_card1 << "and";
break;
}
switch(dealer_card2){
case 1: cout << "Ace and ";
break;
case 11: cout << "Jack and ";
break;
case 12: cout << "Queen and ";
break;
case 13: cout << "King and ";
default: cout << dealer_card2 << "and";
break;
}
cout << "\n" << "\n" << "You have ";
switch (player_card1){
case 1: cout << "Ace and ";
break;
case 11: cout << "Jack and ";
break;
case 12: cout << "Queen and ";
break;
case 13: cout << "King and ";
break;
default: cout << player_card1 << " and ";
break;
}
switch (player_card2){
case 1: cout << "Ace";
break;
case 11: cout << "Jack";
break;
case 12: cout << "Queen";
break;
case 13: cout << "King";
break;
default: cout << player_card2;
break;
}
cout << "\n";
int dealer_total = dealer_card1 + dealer_card2;
int player_total = player_card1 + player_card2;
if ((player_card1 == 1) && (player_card2 == 10|11|12|13))
cout << "Blackjack! You Win !!" << endl;
else
if ((player_card2 == 1) && (player_card1 == 10|11|12|13))
cout << "Blackjack! You Win !!" << endl;
else
if (player_total > dealer_total)
cout << "\n" << "You Win!!!"<< endl;
else
cout << "\n" << "You lose" << endl;
{
cout << "\n" << "Do you want to play again? (y/n): ";
cin >> ans;
while ((ans == 'n') && (ans == 'N'));
}
return 0;
}
thank you both this code was driving me mad.