• C


i want to ask about how to build the black jack with using the c programming. i was wondering with other people whois making the same program as mine.
the matters are:

A pack has 52 cards consisting of 4 suits: Diamonds, Spades, hearts and Clubs. Each suite has cards 1 to 10 and J, Q, K

A card taken from a pack of cards cannot be replaced

The valid card value for Black jack is 16 to 21

The player and the computer are first given 100 credits each for each round of games

The player has to place bet (of credits) before each game

The Player and the Computer are first given 2 cards each using C randomising fucntion rand()

The plauer can decide to whether draw a next card or not

The game ends when both the player and the computer do not want any more cards

The player playing with computer cannot see the cards is holding unless until both players ends the games (by not needing any more cards)

The program need to make the computer take a card if its card value is 15 and below

A round can consist of many games. A round ends when either the Player or the computer has 0 credits or if the player wish to end it

When a round(of games) ends, the date, time, and the credits of both player and computer are written to a text file

When the user wish to see the game history, the program would read from this text file.

The rules:
have to use a card data structure of 2 fields :
  Suit (of character type can be "D", "H", "C", or "S")
  Value (of character type, can be "1" to "10" and "J", "Q", "K")

May apply static (array) or dynamic (pointers) implementation

Game histore records are to be saved into a text file

May take any logical assumptions in the implementation

These all the points and rules are actually about the information that i needed concerning to the project i did,
i m just want to make sure, whether its correct or not, because i think i did in the wrong formulae or ways.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

we don't do your homework FOR you here at EE, but if you show us what you have so far and what you'er getting stuck on, then maybe we can help.

Dosent Blackjack have three deck of cards?
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.


The C Programming Language -- Brian W. Kernighan, Dennis M. Ritchie;

in this book there is a comprehensive help of doing such thing.

(or was it in "A Book on C":
A Book on C : Programming in C -- Al Kelley, Ira Pohl; )
Lukito, i have this programm, as C++ text (tested with BC 5.01 ,Windows) with using OWL. Dou you want it?
Right you EMail.
BTW: i don't think, that it is homework.
I have this on my chat room which is written in c, and this is what I did:

As a general, I set up 4 decks and randomized them all, 52*4-1 = 207, then assigned values to them through mod, ex:

// x is the random number

if (x%13=2)
   sprintf("2 of");
if (x%52=2)

See if that might make it easier, it worked for me and was the best way I could think of to get a truely random deck, just like the casinos have, except you can get your money back.
#include <stdlib.h> //For random nums..
#include <stdio.h>
#include <conio.h>

char *Cards[] = {

char *Suites[] = {

struct Card_S
  char card;
  char Suite;

Card_S Deck[52]; //Full Deck!

//Switches 2 cards in the deck around..
void Switch(int C1, int C2)
  int temp;
  temp = Deck[C1].card;
  Deck[C1].card = Deck[C2].card;
  Deck[C2].card = temp;
  temp = Deck[C1].suite;
  Deck[C1].suite = Deck[C2].suite;
  Deck[C2].suite = temp;

void Shuffle(int times)
  int ctr;
  int Card1, Card2; //Which cards to swap
  //Switch Random cards X amount of times.
  for (ctr=0;ctr<times;ctr++)
    Card1 = rand()%52; //0-51...    
    Card2 = rand()%52;

  int ctr; //A counter
  int Computer_Cards[20];
  int Amount_Computer_Cards;
  int Player_Cards[20];
  int Amount_Player_Cards;
  int DeckCard;
  char Done = 0;
  char Key;
//Should never have more than 20 cards!
  for (ctr=0;ctr<52;ctr++)
    Deck[ctr].card = (ctr/4);
    Deck[ctr].suite = (ctr%4);
  randomize(); //Sets up randomizing!
  //Sets all cards in order...
  Shuffle(200); //How many times to loop
  Player_Cards[0] = 0;
  Computer_Cards[0] = 1;
  Player_Cards[1] = 2;
  Computer_Cards[1] = 3;
  Amount_Player_Cards = 2;
  Amount_Computer_Cards = 2;
  Deck_Card = 4; //Next card.
  //Deal first 4 cards!
  while (!Done)
    printf("(H)it or (S)tay");
    Key = getch();
    if (Key == 'h' || Key == 'H')
    else if (Key == 's' || Key == 'S')
      Done = 1;
  //Have to add stuff for computer, and probably
//some checks to see if player busted and whatnot.
//simple enough, any questions, don't fail my answer
//just tell me you need more help!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Shuffle in the Proposed Answer is not really a fair shuffle.
(although the biases may not matter much for game purposes,
especialy given that the limitations of the rand function probably leasd to an even biger bias)
LukitoAuthor Commented:
Adjusted points to 70
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.