Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <cstdlib>
- using namespace std;
- int main() {
- int value = 1;
- while (value == 1){
- cout<<"Enter how much you would like to bet!! :";
- int betmoney;
- cin>>betmoney;
- char card_type[4][15] = {
- "Diamonds", "Hearts", "Spades", "Clubs"
- };
- int card_number[13] = {
- 1,2,3,4,5,6,7,8,9,10,10,10,10
- };
- char card_name[13][15] = {
- "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
- };
- int playerrandomcard1;
- playerrandomcard1 = rand() % 12 + 0;
- \
- int playerrandomsuit1;
- playerrandomsuit1 = rand() % 3 + 0;
- int playerrandomcard2;
- playerrandomcard2 = rand() % 12 + 0;
- int playerrandomsuit2;
- playerrandomsuit2 = rand() % 3 + 0;
- int playertotal = playerrandomcard1 + playerrandomcard2;
- cout <<"Your first card is a "<<card_name[playerrandomcard1]<<" of "<<card_type[playerrandomsuit1]<<"!"<<endl;
- cout <<"Your second card is a "<<card_name[playerrandomcard2]<<" of "<<card_type[playerrandomsuit2]<<"!\n"<<endl;
- int dealerrandomcard1;
- dealerrandomcard1 = rand() % 12 + 0;
- int dealerrandomsuit1;
- dealerrandomsuit1 = rand() % 3 + 0;
- int dealerrandomcard2;
- dealerrandomcard2 = rand() % 12 + 0;
- int dealerrandomsuit2;
- dealerrandomsuit2 = rand() % 3 + 0;
- int dealertotal = dealerrandomcard1 + dealerrandomcard2;
- cout <<"The Dealer's first card is a "<<card_name[dealerrandomcard1]<<" of "<<card_type[dealerrandomsuit1]<<"!"<<endl;
- cout <<"The Dealer's second card is unknown!"<<endl;
- int value3 = 5;
- while (playertotal < 21 && value3 == 5){
- cout<<"Will you hit or stand? enter 1 for hit and 2 for stand: ";
- int hitchoice;
- cin>> hitchoice;
- if (hitchoice == 1){
- int newplayercard = rand() % 12 + 0;
- int newplayersuit = rand() % 3 + 0;
- playertotal = playertotal + newplayercard;
- cout <<"Your new card is a "<<card_name[newplayercard]<<" of "<<card_type[newplayersuit]<<" ! \n";
- cout<<"Your new total is "<<playertotal<<"."<<endl;
- if (playertotal > 21){
- cout<<"Sorry, you lose!\n";
- cout<<"You have lost your "<<betmoney<<" dollars.";
- break;
- }
- else{
- continue;
- }
- }
- else if (hitchoice == 2){
- cout <<"The dealers second card is a "<<card_name[dealerrandomcard2]<<" of "<<card_type[dealerrandomsuit2]<<"!\n"<<endl;
- while (dealertotal <= 17){
- int dealerhitcard = rand() % 12 + 0;
- int dealerhitsuit = rand() % 3 + 0;
- cout <<"The dealer hit a "<<card_name[dealerhitcard]<<" of "<<card_type[dealerhitsuit]<<" ! \n";
- dealertotal = dealertotal + dealerhitcard;
- cout<<"The dealers total is now "<<dealertotal<<"! \n";
- if (dealertotal > 21){
- cout<<"The dealer busted! you win!\n";
- cout<<"You won "<<betmoney * 2<< " dollars!";
- value3 = 6;
- }
- else if (dealertotal > 17){
- value3 = 6;
- }
- }
- }
- if (playertotal > dealertotal){
- cout<<"You win! \n";
- cout<<"You won "<<betmoney * 2<< " dollars!";
- }
- else if (playertotal < dealertotal){
- cout<<"You lose! \n";
- cout<<"You lost your "<<betmoney<< " dollars.";
- }
- else{
- cout<<"Its a tie!\n";
- cout<<"No money lost or won";
- }
- }
- cout<<"Would you like to play again? enter 1 for yes and 2 for no";
- int playagainchoice;
- cin>>playagainchoice;
- if (playagainchoice == 1){
- cout<<"OK \n";
- }
- else if (playagainchoice == 2){
- value = 2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement