
April 10th, 2006, 01:14 PM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 1
Time spent in forums: 3 m 58 sec
Reputation Power: 0
|
|
|
Help With Blackjack Program
I am just starting to learn C++ and this is what I have so far. I have comments in place of what I would like my program to be able to do. I think I will be able to do everything once I figure out how to assign a number value to all of the cards. If anyone could please help or give any advice at all it would be greatly greatly appreciated...
Code:
#include <iostream>
using namespace::std;
#include <time.h>
#include <string>
struct Card
{
string face;
string suit;
bool used;
};
void fillDeck( Card * , string [], string []);
void shuffle( Card * );
int dealOneCard( Card * );
int PlayOrRules, Bet, Bankroll, HSDSB;
int main()
{
cout << "Welcome to Blackjack!" << endl;
cout << "Please press 1 to play Blackjack or 2 to see the rules" << endl;
cin >> PlayOrRules;
if ( PlayOrRules == 2) {
cout << "Here are the Rules for Blackjack" << endl;
cout << "The Goal of Blackjack is to get more than the dealer without going over 21." << endl;
cout << "The Dealer must hit on 16 or below." << endl;
cout << "There is a 5 card maximum." << endl;
cout << "When you double you are only dealt one more card." << endl;
cout << "You can buy Insurance when the Dealer is showing an Ace." << endl;
cout << "When you buy Insurance and the Dealer has Blackjack you push" << endl;
cout << "You can split any pair." << endl;
cout << "A natural blackjack pays 2.5" << endl;
return main();
}
if ( PlayOrRules != 1 && PlayOrRules !=2) {
cout << "That is not a valid Option." << endl;
cout << "Please Press 1 To Play and 2 To See Rules" << endl;
return main();
}else{
cout << "How much money would you like to play with today?" << endl;
cin >> Bankroll;
cout << "Thank you! You have " << Bankroll << " dollars to spend." << endl;
cout << "How much of your bankroll would you like to bet?" << endl;
cin >> Bet;
if (Bet > Bankroll) {
cout << "You do not have that much money!" << endl;
cout << "How much of your bankroll would you like to bet?" << endl;
cin >> Bet;
}else{
srand(time(0));
Card deck[52];
string face[] = {"Ace", "Two", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King"};
string suit[] = {"Hearts", "Diamonds", "Clubs", "Spades"};
fillDeck(deck,face,suit);
shuffle(deck);
int temp=0;
cout << "Your First Card is the ";
temp = dealOneCard(deck);
cout << deck[temp].face << " of " << deck[temp].suit << endl;
// Store in PlayerTotal
cout << "Your Second Card is the ";
temp = dealOneCard(deck);
cout << deck[temp].face << " of " << deck[temp].suit << endl;
// Store in PlayerTotal
cout << "The Dealer Shows the ";
temp = dealOneCard(deck);
cout << deck[temp].face << " of " << deck[temp].suit << endl;
temp = dealOneCard(deck);
//store in DealerTotal
/*
if(PlayerTotal == 21 && DealerTotal !=21){
cout << "You have Blackjack!" << endl;
cout << "You Win!" << endl;
cout << "You now have " << Bankroll + (Bet * 2.5)
if(PlayerTotal == 21 && DealerTotal ==21){
cout << "You both have Blackjack!" << endl;
cout << "You Push!" << endl;
cout << "You now have " << Bankroll << " dollars!" <<endl;
*/
cout << "What would you like to do?" << endl;
cout << "Press 1 to Hit" << endl;
cout << "Press 2 to Stand" << endl;
cout << "Press 3 to Double" << endl;
//if(deck[temp].face == deck[temp].face){
// cout << "Press 4 to Split" << endl;
//if(deck[temp].face == 11){
// cout << "Press 5 to Buy Insurance" << endl;
cin >> HSDSB;
if(HSDSB = 1)
cout << "Your next card is the ";
temp = dealOneCard(deck);
cout << deck[temp].face << " of " << deck[temp].suit << endl;
// if(PlayerTotal > 21){
// cout << "You Busted!"
// cout << "You lose!"
// Bankroll = Bankroll - Bet;
// cout << "You now have " << Bankroll << " dollars!" <<endl; }
// go to Would you like to play Again?
// if yes go to how much would you like to bet?
// If no
//(CurrentBankroll > InitialBankroll) cout << "Congrats you won " << CurrentBankroll - Initial Bankroll << endl;
//(CurrentBankroll < InitialBankroll) cout << "Sorry you lost " << InitialBankroll - CurrentBankroll << endl;
cout << "What would you like to do?" << endl;
cout << "Press 1 to Hit" << endl;
cout << "Press 2 to Stand" << endl;
cin >> HSDSB;
// only lets you hit once... change it to do while loop... as long as PlayerTotal <21
if(HSDSB = 2){
// cout << "The Dealer has " << DealerTotal << endl;
// {if(DealerTotal > PlayerTotal){
// cout << "You lose!" << endl;}
// Bankroll = Bankroll - Bet;
// cout << "You now have " << Bankroll << " dollars!" <<endl; }}
// if(PlayerTotal > DealerTotal){
// cout << "You win!" << endl;}
// Bankroll = Bankroll + Bet;
// cout << "You now have " << Bankroll << " dollars!" <<endl; }}
// if(PlayerTotal == DealerTotal){
// cout << "You push!" << endl;
// cout << "You now have " << Bankroll << " dollars!" <<endl; }}
// if(HSDSB = 3){
// cout << "Your next Card is the ";
// temp = dealOneCard(deck);
// cout << deck[temp].face << " of " << deck[temp].suit << endl;
// cout << "The Dealer shows " << DealerTotal << endl;
// {if(DealerTotal > PlayerTotal){
// cout << "You lose!" << endl;}
// Bankroll = Bankroll - Bet;
// cout << "You now have " << Bankroll << " dollars!" <<endl; }}
// if(PlayerTotal > DealerTotal){
// cout << "You win!" << endl;}
// Bankroll = Bankroll + Bet;
// cout << "You now have " << Bankroll << " dollars!" <<endl; }}
// if(PlayerTotal == DealerTotal){
// cout << "You push!" << endl;
// cout << "You now have " << Bankroll << " dollars!" <<endl; }}
// if(HSDSB = 4){
// (Bet * 2 <= Bankroll)
// if(HSDSB = 5){
// (Bet * 2 <= Bankroll)
}}}}
void fillDeck( Card * workDeck, string workFace[], string workSuit[])
{
for(int i=0; i<52; i++)
{
workDeck[i].face = workFace[i%13];
workDeck[i].suit = workSuit[i/13];
workDeck[i].used = false;
}
}
void shuffle( Card * workDeck)
{
for(int i=0; i<52; i++)
{
int j=rand() % 52;
Card temp = workDeck[i];
workDeck[i] = workDeck[j];
workDeck[j] = temp;
}
}
int dealOneCard( Card * workDeck )
{
int j=0;
while(workDeck[j].used == true)
j++;
if(j<52)
{
workDeck[j].used = true;
return j;
}
else
return -1;
}
Last edited by B-Con : April 10th, 2006 at 05:30 PM.
Reason: added [code] tags
|