I am trying to use a structure to store the card value, the card name, and the suit name for a deck of 52 cards in a blackjack program.
The structure is globally defined:
Code:
struct cards{
int cardval; // value of card
string suitname; // name of suit
string cardname; // name of card
}card[52];
In the main function, card is passed to the function deckgen:
Code:
deckgen(card);//creates deck and names card values
Deckgen is in a header file:
Code:
#ifndef DECKGEN_H
#define DECKGEN_H
# include <iostream>
# include <string>
using namespace std;
void deckgen(cards [52]);
void deckgen(cards card[52])
{
// Setting card values
int num;
int cardnum = 1;
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 12; j++)
{
if (j < 9)
num = j+2;
else if (j <12)
num = 10;
else num = 11;
card[cardnum].cardval = num;
//Naming suits.
switch(i){
case 0:
card[cardnum].suitname = "clubs";
break;
case 1:
card[cardnum].suitname = "diamonds";
break;
case 2:
card[cardnum].suitname = "hearts";
break;
case 3:
card[cardnum].suitname = "spades";
break;}
//Naming Cards.
switch(cardrand){
case 0:
card[cardnum].cardname = "two";
break;
case 1:
card[cardnum].cardname = "three";
break;
case 2:
card[cardnum].cardname = "four";
break;
case 3:
card[cardnum].cardname = "five";
break;
case 4:
card[cardnum].cardname = "six";
break;
case 5:
card[cardnum].cardname = "seven";
break;
case 6:
card[cardnum].cardname = "eight";
break;
case 7:
card[cardnum].cardname = "nine";
break;
case 8:
card[cardnum].cardname = "ten";
break;
case 9:
card[cardnum].cardname = "jack";
break;
case 10:
card[cardnum].cardname = "queen";
break;
case 11:
card[cardnum].cardname = "king";
break;
case 12:
card[cardnum].cardname = "ace";
break;}
cardnum ++;
}
}
}
#endif
My first problem is that I am getting the error messages:
"error C2065: 'cards' : undeclared identifier"
and
"error C2182: 'deckgen' : illegal use of type 'void' " for line 8 of deckgen.
Secondly, I do not think that my code now stores the variables correctly in the structure card[52]. Namely, I do not think these values can be used in other functions.
How can I correct these problems?
Thank you,
J