Looking for some help from the community. I can't seem to find the exact answer to my question after browsing around.
I am in the beginning stages of a program and after declaring a struct (cardStruct) then declaring an array of struct type (cardStruct deck[MAX_CARDS]), I am trying to access the array through my function FormCards.
Here's my problem, hopefully you guys can point me in the right direction.
Here's my code:Code:cards.cpp:39: error: variable or field 'FormCards' declared void cards.cpp:39: error: 'cardStruct' was not declared in this scope
Code:#include <iostream>#include <cstdlib> #include <ctime> using namespace std; //Global Constants const int MAX_CARDS = 52; //Represents the size of the deck of cards const int MAX_SUIT = 13; //Function Declarations void FormCards (); int main () { enum SuitType {CLUBS, HEARTS, SPADES, DIAMONDS}; //Enum type to represent each card's suit struct cardStruct { SuitType suit; int value; int point; }; cardStruct deck[MAX_CARDS]; } void FormCards (cardStruct deck[]) { int i, k; //loop index int index = 0; //Used for assigning points and values in nested for loop //For loop assigns suit //13 cards per suit for (i = 0; i < MAX_CARDS; i++) { if (i < 13) deck[i].suit = DIAMOND; else if (i < 26) deck[i].suit = CLUB; else if ( i < 39) deck[i].suit = HEART; else deck[i].suit = SPADE; } //Nested for loop assigns values and points for (i = 0; i < MAX_SUIT; i++) { //assign values deck[index].value = k + 1; //assign points //HEART card sless than 10 has a point of 5 //HEART cards of J, Q, K have points of 10 if (deck[index].suit == HEART) { if (deck[index].value >= 10) deck[index].points = 10; else deck[index].points = 5; } //Queen of SPADE has a point of 100 else if (deck[index].suit == SPADE && deck[index].value == 12) deck[index].points = -100; //Rest of the cards will have 0 points else deck[index].points = 0; index++; //Increase index by 1 }



LinkBack URL
About LinkBacks


