this black jack game works but when u bust it exits the box.
Code:#include<iostream.h> #include<time.h> #include<stdlib.h> //Isaac Gibbs //BlackJack that is going to work but this is our first time back on the computers since January //nice one Pedro, killing Bobs ghost but thats ok now int main(void) { int money = 500, money1, card1, card2, cardy, cardd = 16;//money is the amount of money that you start with, money1 is the amount of money that you gamble on, card1 is you first card, card2 is your second card, card3 is any extra card that you might want like if you want to hit or something, cardd is the combined cards of the dealer, cardy are your cards. char hit, play, quit;//hit is if you want a hit or not, play is if you want to play or not, quit is if you want to quit or not srand((unsigned)time(NULL));// signs a random interger to a nullified time so when ever in others words it enables random intergers cout << "This is a Blackjack game!\n"; cout << "You will never beat me hahahahaha.\n"; cout << "Do you want to play y or n???\n";//asking if player wants to actually play cin >> play;//using the character play to ask if they if (play == 'y'){ cout << "So, how much money do you feel like losing today? You start with "<< money <<"\n"; } while (play == 'y'){ card1 = 2+rand()%10;//card1 is two plus a randomized interger up to Eleven card2 = 2+rand()%10;//card2 is two plus a randomized interger up to eleven cout << "You have "<< money <<" dollars.\n"; cout << "HELLO put in your bet amount!!!!! \n"; cin >> money1;//the amount of money that you want to bet if (money == 0)//if money equals zero {cout << "Sorry you have no more money...You lose.\n";//then this is displayed return main();}//the program restarts itself if (money1 > money)//if the money if higher than than it says this {cout << "You don't have that much money!!!\n"; return main();//returns to the top of the program cout << "\n";} cout << "You have chosen "<< money1 <<" dollars.\n"; money = money - money1;//money equals the amount of money you bet minus the money you started off with cout << "You have "<< money <<" dollars left to your name.\n";//prints out how much money that you have left cout << "Your cards are "<< card1 <<", and "<< card2 <<".\n";//deals cards cardy = card1 + card2;//totals the cards that you have if (cardy > 21)//if the sum of the cards is over 21 then { cout << "Sorry you busted... You lose.\n";//it tells you that you lose return 0;}//stops program else cout << "They add up to "<< cardy <<", would you like a hit y or n?\n";//the add up to a card number cin >> hit;//if you to hit this is the variable while (hit == 'y'){//while hit eqauls y then all this happens card1 = 2+rand()%10;//card1 is two plus a randomized interger up to Eleven cout << "Your next card is "<< card1 <<".\n"; cardy = card1 + cardy;//it adds up to the total of the two cards that you had before if (cardy > 21)//again if the card equals anything higher than 21 then this is displayed { cout << "Sorry you busted. you lose all your money...\n"; return 0;} else cout << "They add up to "<< cardy <<", would you like a hit y or n?\n";//the add up to a card number cin >> hit;}//if you to hit this is the variable}//program ends cardd = 15+rand()%6;//the dealer cards equal a random number from 15 to 21 cout << "The Dealer has "<< cardd <<".\n"; if (cardd > cardy)//if the dealer card number is higher than yours than you lose { cout << "The Dealer wins!!!\n"; cout << "You have a total of "<< money <<" dollars hold on to it!\n";} if (cardd == cardy)//if your card equals the card of the dealer you lose anyway { cout << "The Dealer wins!!!\n"; cout << "You have a total of "<< money <<" dollars hold on to it!\n";} if (cardy > cardd)//if your cards are higher than the dealers cards you win { cout << "The Player wins!!!\n"; money = money + 2 * money1;//the money you bet is doubled plus the rest of the money you had cout << "You have a total of "<< money <<" dollars hold on to it!\n";} cout << "Do you want to play again, y or n???\n";//asks if you want to play again cin >> quit;//character for quiting if (quit == 'n')//if quit equals "n" then it starts from the beginning { cout << "I told you that you couldn't win!!!\n";//if quit equals "y" then this is printed return 0;}//and then the progrom ends } return 0;//end program }



LinkBack URL
About LinkBacks


