I've got this game almost working. When I run it in my complier is "blows" up at this line:

if (facesInHand[numberInHand2][1] != 0 && facesInHand[numberInHand2][2] != 0 && facesInhand[numberInHand2][3] != 0 && facesInhand[numberInHand2][4] != 0 && facesInhand[numberInHand2][13] != 0)
	straight = 1;
		else
	straight = 0;

and continues through the rest of the code, the error messages the complier gives are:

'facesInhand' : undeclared identifier
subscript requires array or pointer type

I've been working at this pretty much straight since about 9am this morning. I have a feeling it is something silly that I am missing but my brain is tired. Any thoughts or suggestions would be greatly appreciated!! If you need anymore infor about the Specs for the game I'd be more then happy to answer them!

Thanks :)

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SUITS 4
#define FACES 13
#define AVAILABLE 0
#define TAKEN 1

void dealACard( char *suits[], char *faces[], int deck [] [FACES], int numberOfHand);
void dealAHand( char *suits[], char *faces[], int deck [] [FACES], int numberOfHand);
int analyzeHand( int suitsInHand[][SUITS], int facesInHand[][FACES], int numberInHand2, int handValue[], int highCard[]);

int suitsInHand[10][5] = {0};
int facesInHand[10][14] = {0};
int totalHandValue[10] = {0};
main () {

	char * suits[4] = {"Hearts", "Diamonds", "Spades", "Clubs"};
	char *faces[13] = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"};

	int deck [4][13] = {AVAILABLE};
	int i, numberOfPlayers, numberOfHand = 0, j, numberInHand2 = 0, maxValue = totalHandValue[1];
	int handValue, highCard;
	srand(time(NULL));

	printf("Enter # of players between 2 and 10 \n");
	scanf("%i", &numberOfPlayers);

	for (i = 0; i < numberOfPlayers; i++){
		numberOfHand = numberOfHand + 1;
		dealAHand(suits, faces, deck, numberOfHand);

	}


	for (i = 1; i <= numberOfPlayers; i++){
		printf("\n");
		for (j = 1; j <= 4; j++){
			printf("%i , ", suitsInHand[i][j]);
		}
	}
	for (i = 1; i <= numberOfPlayers; i++){
		printf("\n");
		for (j = 1; j <= 13; j++){
			printf("%i, ", facesInHand[i][j]);
		}
	} 
	for(i = 1; i <= numberOfHand; i++){
		numberInHand2 = numberInHand2 +1;
		analyzeHand(suitsInHand, facesInHand, numberInHand2, handValue, highCard);



	}

	// determine winner

	for( i = 1; i <= numberOfPlayers; i++){
		totalHandValue[i] = totalHandValue;
	}

	maxValue = totalHandValue[1];
	for(i = 2; i <= numberOfPlayers; i++){
		if(totalHandValue[i] > maxValue){
			maxValue = totalHandValue[i];
		}
	}
	if(maxValue == totalHandValue[1]){
		printf("Hand One is the winner!! \n");
	}

	if(maxValue == totalHandValue[2]){
		printf("Hand Two is the winner!! \n");
	}
	if(maxValue == totalHandValue[3]){
		printf("Hand Three is the winner!! \n");
	}

	if(maxValue == totalHandValue[4]){
		printf("Hand Four is the winner!! \n");
	}
	if(maxValue == totalHandValue[5]){
		printf("Hand Five is the winner!! \n");
	}
	if(maxValue == totalHandValue[6]){
		printf("Hand Six is the winner!! \n");
	}
	if(maxValue == totalHandValue[7]){
		printf("Hand Seven is the winner!! \n");
	}
	if(maxValue == totalHandValue[8]){
		printf("Hand Eight is the winner!! \n");
	}
	if(maxValue == totalHandValue[9]){
		printf("Hand Nine is the winner!! \n");
	}
	if(maxValue == totalHandValue[10]){
		printf("Hand Ten is the winner!! \n");
	}


	system("pause");

}

void dealAHand( char *suits[], char *faces[], int deck [] [FACES], int numberOfHand) {
	int i;

	for(i = 0; i < 5; i++)
		dealACard(suits, faces, deck, numberOfHand);
	printf("\n");
}

void dealACard( char *suits[], char *faces[], int deck [] [FACES], int numberOfHand){
	int suitIndex, faceIndex;

	suitIndex = rand() %4;

	//printf("%i \n", numberOfHand);

	if(suitIndex == 0){ 
		suitsInHand[numberOfHand][1] = suitsInHand[numberOfHand][1] + 1;
	}
	printf("%i, \n", suitsInHand[numberOfHand][1]);


	if (suitIndex == 1){
		suitsInHand[numberOfHand][2] = suitsInHand[numberOfHand][2] + 1;
	}
	printf("%i, \n", suitsInHand[numberOfHand][2]);



	if (suitIndex == 2){
		suitsInHand[numberOfHand][3] = suitsInHand[numberOfHand][3] + 1;
	}
	printf("%i, \n", suitsInHand[numberOfHand][3]);



	if (suitIndex == 3){
		suitsInHand[numberOfHand][4] = suitsInHand[numberOfHand][4] + 1;
	}
	printf("%i, \n", suitsInHand[numberOfHand][4]);






	faceIndex = rand() % 13;

	if (faceIndex == 0) {
		facesInHand[numberOfHand][1] = facesInHand[numberOfHand][1] + 1;
	}
	if (faceIndex == 1) {
		facesInHand[numberOfHand][2] = facesInHand[numberOfHand][2] + 1;
	}

	if (faceIndex == 2) {
		facesInHand[numberOfHand][3] = facesInHand[numberOfHand][3] + 1;
	}
	if (faceIndex == 3) {
		facesInHand[numberOfHand][4] = facesInHand[numberOfHand][4] + 1;
	}
	if (faceIndex ==4) {
		facesInHand[numberOfHand][5] = facesInHand[numberOfHand][5] + 1;
	}
	if (faceIndex == 5) {
		facesInHand[numberOfHand][6] = facesInHand[numberOfHand][6] + 1;
	}
	if (faceIndex == 6) {
		facesInHand[numberOfHand][7] = facesInHand[numberOfHand][7] + 1;
	}
	if (faceIndex == 7) {
		facesInHand[numberOfHand][8] = facesInHand[numberOfHand][8] + 1;
	}
	if (faceIndex == 8) {
		facesInHand[numberOfHand][9] = facesInHand[numberOfHand][9] + 1;
	}
	if (faceIndex == 9) {
		facesInHand[numberOfHand][10] = facesInHand[numberOfHand][10] + 1;
	}
	if (faceIndex == 10) {
		facesInHand[numberOfHand][11] = facesInHand[numberOfHand][11] + 1;
	}
	if (faceIndex == 11) {
		facesInHand[numberOfHand][12] = facesInHand[numberOfHand][12] + 1;
	}
	if (faceIndex == 12) {
		facesInHand[numberOfHand][13] = facesInHand[numberOfHand][13] + 1;
	}

	while (deck[suitIndex] [faceIndex] == TAKEN){
		suitIndex = rand() % 4;
		faceIndex = rand() % 13;
	}

	deck[suitIndex][faceIndex] = TAKEN;

	printf("%s of %s \n", faces[faceIndex], suits[suitIndex]);

}

int analyzeHand( int suitsInHand[][SUITS], int facesInHand[][FACES], int numberInHand2, int handValue[], int highCard[]){
	int flush, straight, threeOfAKind, twoPair, onePair,  straightFlush, fourOfAKind, fullHouse,
		num_consec = 0, rank, numberOfPairs = 0, highCard2 = 13,  i;
	// check for flush

	for( i = 1; i <= 4; i++){
		if(suitsInHand[numberInHand2][i] = 5)
			flush = 1;
		else
			flush = 0;
	}


	//check for straight
	rank = 0;
	while ( facesInHand[numberInHand2][rank] == 0){
		rank++;
	}
	if (facesInHand[numberInHand2][rank + 1] != 0 && facesInHand[numberInHand2][rank + 2] != 0 && facesInHand[numberInHand2][rank + 3] != 0 && facesInHand[numberInHand2][rank +4] != 0)
		straight = 1;
	else
		straight = 0;

	//	if (facesInHand[numberInHand2][1] != 0 && facesInHand[numberInHand2][2] != 0 && facesInhand[numberInHand2][3] != 0 && facesInhand[numberInHand2][4] != 0 && facesInhand[numberInHand2][13] != 0)
	//straight = 1;
	//	else
	//straight = 0;


	// check for fourOfAKind
	fourOfAKind = 0;
	for( i = 1; i <= 13; i++){
		if(facesInhand[numberInHand2][i] == 4){
			fourOfAKind = 1;
		}


	}

	// check for threeOfAKind

	for ( i = 1; i <= FACES; i++){
		if(facesInhand[numberInHand2][i] == 3)
			threeOfAKind = 1;
		else
			threeOfAKind = 0;
	}


	// check for twoPair

	for ( i = 1; i <= FACES; i++){
		if(facesInhand[numberInHand2][i] == 2)
			onePair = 1;
		numberOfPairs = numberOfPairs + 1;


		if (numberOfPairs == 2)
			twoPair = 1;
		else
			numberOfPairs = 0;
	}

	// check for highCard

	for ( i = 13; i <= 1; i--){
		if (facesInHand[numberInHand2][i] == 0){
			highCard2 = highCard2 - 1;
		}
		highCard = highCard2;
	}

	// calculate handValue

	if (straight == 1 && flush == 1){
		handValue = 105;
	}
	if (fourOfAKind == 1){
		handValue = 92;
	}
	if (threeOfAKind == 1 && twoOfAKind == 1){
		handValue = 79;
	}
	if (flush == 1){
		handValue = 66;
	}
	if (straight == 1){
		handValue = 53;
	}

	if (threeOfAKind == 1){
		handValue = 40;
	}

	if(twoPair == 1){
		handValue = 27;
	}
	if (onePair == 1){
		handValue = 14;
	}
	totalHandValue = handValue + highCard;
	return totalHandValue;

}

Recommended Answers

All 4 Replies

facesInhand is not the same than facesInHand

commented: damn, you're good. +7

also, facesInhand[numberInHand2][13] is beyond the array. The array stops at 12, not 13.

facesInhand is not the same than facesInHand

I'd been working on this literally ALL DAY!! I knew it was something silly. Thank you so much for catching it. I greatly appreciate it!!

Once I made the changes you and WaltP gave it started working!! Thanks a billion!!

Sincerely,
geekgirl2011

Huge Thanks!! As soon as I made the changes you guys suggested the game started playing!! MUCH MUCH Thanks!! :)

Sincerely,
geekgirl2011

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.