Card Creation with Structs

Hello,

I'm trying to make a card creation and shuffling program in my C++ class, and I'm having a lot of trouble coming up with how the structs interact with one another. For instance, in the for loop that I have, I tend to get an error of C2274 on the line where the enum is taken into account.

// cardGame.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

struct singleCard
{
int rank;
enum suit { CLUBS, DIAMONDS, HEARTS, SPADES};
};


struct playDeck
{
singleCard card[52];
int cardIndex;
} deck;


struct playerHand
{
singleCard cardsInHand[13];
int handCounter;
};


int main()
{
char playAgain;

deck.cardIndex = 51;
for ( int i = 0; i < 13; i++)
{
for ( int j = 0; j < 4; j++)
{
deck.card[deck.cardIndex].rank = i;
deck.card[deck.cardIndex].suit = j;
deck.cardIndex--;
cout << deck.cardIndex << endl;
}
}

do
{


cout << "\nWould you like to play again? (y/n): ";
cin >> playAgain;

} while ( playAgain == 'y' );



cout << "\nPlease enter a character and press enter to quit: ";
char quitGame;
cin >> quitGame;

return 0;
}
Maybe you should try it like this:
1
2
3
4
5
6
struct singleCard
{
  int rank; 
  enum suit { CLUBS, DIAMONDS, HEARTS, SPADES};
  suit Suit;
};


and then in your loop:
 
deck.card[deck.cardIndex].Suit = j;


The syntax of enums is like the the syntax of classes in some ways. You declare your enum with
 
enum enumName { STATES...};

afterwards you can creates enums of the type enumName.
1
2
enumName enum1;
enumName enum2;


Topic archived. No new replies allowed.