Okay, so I am have a bit of trouble with my program. The program itself will deal two hands of cards, shuffle the deck, and then deal another two hands. At the moment I have most of the code down I believe, but I cannot for the life of me figure out how to declare the numbers that I want in the array of card[]. That and I cannot figure out how to do the constructor for the class, aka theDeck. When I complied it, it came up with the error "ISO C++ forbids declaration of `theDeck' with no type". Sorry about the code being so long, but if anyone could help with figuring out what is wrong with my constructor and how to declare the numbers in the array I would be very grateful.
Code:
class Cards { private: int card[51]; public: theDeck(int c); void Deal (); void Shuffle (); } Cards::theDeck(int c[]) { card[51]=c[51]; } void Cards::Shuffle() { srand(time(NULL)); for (int i=0; i<(52-1); i++) { int r = i + (rand() % (52-i)); int temp = card[i]; card[i] = card[r]; card[r] = temp; } return; } void Cards::Deal() { int r, a; srand(time(NULL)); r=(rand()%51); a=card[r]; if (a>100 && a<114) { if (a==101) cout <<"Ace of Clubs" <<endl; else if (a==102) cout <<"Two of Clubs" <<endl; else if (a==103) cout <<"Three of Clubs" <<endl; else if (a==104) cout <<"Four of Clubs" <<endl; else if (a==105) cout <<"Five of Clubs" <<endl; else if (a==106) cout <<"Six of Clubs" <<endl; else if (a==107) cout <<"Seven of Clubs" <<endl; else if (a==108) cout <<"Eight of Clubs" <<endl; else if (a==109) cout <<"Nine of Clubs" <<endl; else if (a==110) cout <<"Ten of Clubs" <<endl; else if (a==111) cout <<"Jack of Clubs" <<endl; else if (a==112) cout <<"Queen of Clubs" <<endl; else cout <<"King of Clubs" <<endl; } if (a>200 && a<214) { if (a==201) cout <<"Ace of Diamonds" <<endl; else if (a==202) cout <<"Two of Diamonds" <<endl; else if (a==203) cout <<"Three of Diamonds" <<endl; else if (a==204) cout <<"Four of Diamonds" <<endl; else if (a==205) cout <<"Five of Diamonds" <<endl; else if (a==206) cout <<"Six of Diamonds" <<endl; else if (a==207) cout <<"Seven of Diamonds" <<endl; else if (a==208) cout <<"Eight of Diamonds" <<endl; else if (a==209) cout <<"Nine of Diamonds" <<endl; else if (a==210) cout <<"Ten of Diamonds" <<endl; else if (a==211) cout <<"Jack of Diamonds" <<endl; else if (a==212) cout <<"Queen of Diamonds" <<endl; else cout <<"King of Diamonds" <<endl; } if (a>300 && a<314) { if (a==301) cout <<"Ace of Hearts" <<endl; else if (a==302) cout <<"Two of Hearts" <<endl; else if (a==303) cout <<"Three of Hearts" <<endl; else if (a==304) cout <<"Four of Hearts" <<endl; else if (a==305) cout <<"Five of Hearts" <<endl; else if (a==306) cout <<"Six of Hearts" <<endl; else if (a==307) cout <<"Seven of Hearts" <<endl; else if (a==308) cout <<"Eight of Hearts" <<endl; else if (a==309) cout <<"Nine of Hearts" <<endl; else if (a==310) cout <<"Ten of Hearts" <<endl; else if (a==311) cout <<"Jack of Hearts" <<endl; else if (a==312) cout <<"Queen of Hearts" <<endl; else cout <<"King of Hearts" <<endl; } if (a>400 && a<414) { if (a==401) cout <<"Ace of Spades" <<endl; else if (a==402) cout <<"Two of Spades" <<endl; else if (a==403) cout <<"Three of Spades" <<endl; else if (a==404) cout <<"Four of Spades" <<endl; else if (a==405) cout <<"Five of Spades" <<endl; else if (a==406) cout <<"Six of Spades" <<endl; else if (a==407) cout <<"Seven of Spades" <<endl; else if (a==408) cout <<"Eight of Spades" <<endl; else if (a==409) cout <<"Nine of Spades" <<endl; else if (a==410) cout <<"Ten of Spades" <<endl; else if (a==411) cout <<"Jack of Spades" <<endl; else if (a==412) cout <<"Queen of Spades" <<endl; else cout <<"King of Spades" <<endl; } return; } int main() { Cards theDeck; int i, j=1; while (j<=2) { cout <<"Hand " <<j <<endl; if (i=1, i<=5, i++) { theDeck.Deal(); } j++; } theDeck.Shuffle(); j=1; while (j<=2) { cout <<"Hand " <<j <<endl; if (i=1, i<=5, i++) { theDeck.Deal(); } j++; } system("PAUSE"); return 0; }
Comment