C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 10th, 2006, 01:14 PM
Yodasbrthr Yodasbrthr is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 1 Yodasbrthr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old April 10th, 2006, 05:36 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
The traditional way to number a full deck of cards to so assign Ace the value of 1, 2 the value of 2, etc, up to King the value of 13. Do this for each deck.

Then arrange the suite in an order meaningful to you (I usually do something like Hearts, Diamonds, Clubs, Spades) and multiply all the card values in each one by the number they are into that list. ie, multiply all "Heart" cards by 1, all "Diamond" cards by 2, etc. This will give you a list of 52 cards numbered from 1 to 52 (or you can number them 0 to 51 if you wan).

Then, given a number in thie 1 - 52 range, you can figure out what number it is in its given suite by modding it by 13. You can also figure out what suite it's in by peforming integer division on it by 13 and adding 1.
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips.



Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help With Blackjack Program


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT