-
BlackJack Game
Can anyone help me with this code...More details below:
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int CardValue;
int Players[2] = {0};
int main ( void )
{
void showHand ( char *val1, char *val2, char *val3, char *val4 );
int randomNumber(int max);
int HitStay(void);
char *DealCards(int n, int ToWhom);
char *assignCardValue(void);
char *card1;
char *card2;
char *card3;
char *card4;
srand((unsigned int)time(NULL));
card1 = DealCards(1,0);
card2 = DealCards(1,0);
card3 = DealCards(1,1);
card4 = DealCards(1,1);
showHand(card1, card2, card3,"");
printf("You have a total of %d Points\t\t Dealers first card is %2s\n", Players[0], card3);
HitStay();
getchar();
return 0;
}
/* _______________showHand Function_______(uses stdio.h)______________________*/
void showHand ( char *val1, char *val2, char *val3, char *val4 )
{
printf ( "***********\t***********\t\t***********\t***********\n" );
printf ( "*%2s *\t*%2s *\t\t*%2s *\t*%2s *\n", val1, val2,val3, val4);
printf ( "* *\t* *\t\t* *\t* *\n" );
printf ( "* *\t* *\t\t* *\t* *\n" );
printf ( "* *\t* *\t\t* *\t* *\n" );
printf ( "* *\t* *\t\t* *\t* *\n" );
printf ( "* *\t* *\t\t* *\t* *\n" );
printf ( "* %2s *\t* %2s *\t\t* %2s *\t* %2s *\n", val1, val2, val3, val4);
printf ( "***********\t***********\t\t***********\t***********\n\n" );
}
/* ______________randomNumber Function____(uses: stdlib.h and time.h)_________*/
int randomNumber(int max) /* MAX is N + 1 */
{
int Xrand;
Xrand = rand() % max;
return Xrand;
}
/*______________assignCardValue Function__________*/
char *assignCardValue(void)
{
char *CardName[] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
int value[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 };
int r = randomNumber ( 13 );
CardValue = value[r];
return CardName[r];
}
/*____________________DealCards() Function ______________*/
char *DealCards(int n, int ToWhom)
{
int i;
char *cards;
for (i = 0; i = n; i++)
{
cards = assignCardValue();
Players[ToWhom] += CardValue;
break;
}
return cards;
}
/*___________HitStay() Function___________*/
int HitStay(void)
{
return 0;
}
/*________HandleDealersHand() Function_______*/
/*________ShowDealerHand() Function_____*/
Cant seam to get my Loop to work for Hit or Stay Function...
I have a function:
Code:
int HitStay(void)
{
return 0;
}
Inside i need to get the players choice H for Hit and S for Stay...
If the player chooses H thee function DealCards(1,1) is called and the new total of his cards should be printed.
Code:
printf("Your total is %d", Players[0]);
From there the play should be asked again if they wish to Hit or Stay... If they choose stay then the loop should be exited....
Iv tried several times but cant seam to figure out why my while loop doesnt work...
-
Where is the while loop you are having problems with? I didn't see it in the code you posted.
Eigenvalue
[edit]I am obviously obsessed with while loops. Sorry about that!:rolleyes: [/edit]
-
for (i = 0; i = n; i++)
I think you mean:
for (i = 0; i < n; i++)
-
actually what does your game do ???