Help with Blackjack program

This is a discussion on Help with Blackjack program within the C++ Programming forums, part of the General Programming Boards category; I'm trying to write a Blackjack program and I am stuck. HELP! The rules for game that differ from Blackjack ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    17

    Help with Blackjack program

    I'm trying to write a Blackjack program and I am stuck. HELP!
    The rules for game that differ from Blackjack are that aces are always 1. You can't really get a Blackjack but it's for a class and that's what the prof wanted.

    Anyway, I can shuffle the cards and deal the numbers (1-52) where I want them to go but I am trying to assign values and suits to them now and I'm stuck.
    Here's what I have so far:

    Code:
    #include <time.h>
    #include <iostream>
    #include <windows.h>
    #include <iomanip>
    #include <stdio.h>
    #include "gotoxy.h"
    using namespace std;
    
    void Header();
    void ShuffleDeck(int[]);
    void DealTwo (int[]);
    
    int main()
    {
    	const int i=52;
    	int card[i];
    	
    	Header();
    	ShuffleDeck(card);
    
    	
    	DealTwo(card);
    	
    		//printing out headers on screen
    		gotoxy(35, 2);
    		printf("Dealer");
    		gotoxy(4, 7);
    		cout << "Player 1" << "  " << "Player 2" << "  " << "Player 3" << "  " 
    			 << "Player 4" << "  " << "Player 5" << "  " << "Player 6" << "  "
    			 << "Player 7";
    		getchar();
    	return 0;
    }
    
    void Header()
    {
    	cout <<"Welcome To Tom's Casino - Let's Play Blackjack! \n" <<endl;
    }
    
    void ShuffleDeck(int cards[])
    {
    	int i, flags[52], value;
    
    	    srand(time(NULL));
    		for(i=0; i<52; i++)
    			flags[i]=0;
    		for(i=0; i<52; i++)
    		{
    			value = rand()%52;
      
    			while(flags[value])
    				  value = rand()%52;
    
    			cards[i] = value;
    			flags[value] = 1;
    		}
    		
            return;
    }	
    
    void DealTwo(int cards[])
    {
    	int i=0;
    	char ch, pic;
    
    		gotoxy(37, 3);
    		//ch = suitFunc(cards[i], val, pic);
    		
    		cout << setw(2) << cards[i];
    		i++;
    		gotoxy(7, 8);
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		gotoxy(37, 4);
    		cout << setw(2) << cards[i];
    		i++;
    		gotoxy(7, 9);
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		cout << setw(2) << cards[i] << "        ";
    		i++;
    		
    		return;
    
    }
    
    
    /*void suitFunc(int [], int val, char pic)
    {
    	card = cards[i];
    	suitn = card/13;
    	
    	switch (suitn)
    	{
    	case 0: suit = char (3); //heart
    	case 1: suit = char (4); //diamond
    	case 2: suit = char (5); //club
    	case 3: suit = char (6); //spade
    
    	cvalue = cards[i];
    num = cvalue % 13;
    		if num == 0
    			ch = 'A'
    			truevalue = 1;
    		if num > 0 && num < 10
    			
    			truevalue = num + 1;
    
    		if num > 9
    		{
    			truevalue = 10;
    			if(num == 10)
    				ch = 'J'
    			else if (num == 11)
    				ch = 'Q'
    			else if (num == 12)
    				ch = 'K'  
    		}
    	}
    }
    */
    Here is the gotoxy.h code
    Code:
    
    #include <windows.h>
    #include <stdio.h>
    
    void gotoxy(int h, int w)
    {
    	HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
    	if(INVALID_HANDLE_VALUE != hConsole)
    	  {
    	     COORD pos={h, w};
    	     SetConsoleCursorPosition(hConsole, pos);
    	  }
    	return;
    }
    I need to get rid of the numbers I have delt and put in the suits and values.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    > srand(time(NULL));
    Put this at the start of main()
    The only thing you do by calling it multiple times is you keep resetting the generator, so your numbers appear a lot less random than they already do.

    Code:
    		if num == 0
    			ch = 'A'
    			truevalue = 1;
    		if num > 0 && num < 10
    			
    			truevalue = num + 1;
    
    		if num > 9
    		{
    			truevalue = 10;
    			if(num == 10)
    				ch = 'J'
    			else if (num == 11)
    				ch = 'Q'
    			else if (num == 12)
    				ch = 'K'  
    		}
    	}
    Well your first if needs some parentheses ()
    And all your statements need braces {}
    And some of your statements need semicolons as well ;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. blackjack program
    By mackieinva in forum C Programming
    Replies: 8
    Last Post: 09-20-2007, 03:46 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21