Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
long post here:
here's the info for the game: "We play with a deck of cards numbered from one to six which is divided into four suits. First, I deal three cards face up. You are then dealt a single card which you must play upon any one of the three cards. You can play the card onto any card which is either the same numerical value or of the same suit. The one exception to the rule is for the formation of crowns: You may play the card in which the resulting total is seven. Once this is done, that pile is considered a crown. The object of the game is form all three crowns. You lose if you are delt a card which you cannot play"
so i just need to have something generate the three cards randomly and also generate the card you need to play and then just be able to select which card you want to play your card on. [it's simple text based]
here's the code:
#include
#include
#include
#includeconst int HEARTS = 1 ;
const int SPADES = 2 ;
const int DIAMONDS = 3 ;
const int CLUBS = 4 ;
bool deck[24] ;class Stack {
public:
Stack() { crowned = false ; card = 0 ; suit = 0 ; }
~Stack() { /* None needed */ }
bool Valid_Move(int new_val, int new_suit) {if (crowned) { return false ; }
if (card == 0) { return true ; }
if (card == new_val) { return true ; }
if (new_suit == suit) { return true ; }
if ( (new_val + card) == 7) { return true ; }
return false ;
}bool Place(int new_val, int new_suit) {
if ( (new_val + card) == 7) { crowned = true ; }
card = new_val ;
suit = new_suit ;return crowned ;
}bool is_crowned() { return crowned ; }
int get_card() {
if (!crowned) { return ((10*suit) + card) ; }
else return -1 ;
}private:
bool crowned ;
int card ;
int suit ;
} ;int Deal() ;
void Display(int x, int y, int z) ;
string Card_ID(int card) ;int main() {
Stack piles[3] ;
int face, suit, card, drop ;
string name ;
bool lost = false ;
bool won = false ;
bool crowned ;srand ( time(NULL) );
cout " ;
cin >> drop ;
while ( ((drop 3)) ||
!piles[drop-1].Valid_Move(face, suit) ) {
cout " ;
cin >> drop ;
}
drop-- ;
crowned = piles[drop].Place(face, suit) ;
if (crowned) {
cout endl ;
cout "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
cout endl ;
cout "! Congratulations, you have " ;
cout "crowned Stack[" drop+1 "] !" endl ;
cout "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
cout endl endl ;
} else { cout endl ; }
}
won = (piles[0].is_crowned() &&
piles[1].is_crowned() &&
piles[2].is_crowned() ) ;
} while (!lost && !won) ;if (won) {
cout endl ;
cout "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" endl ;
cout "@ You have won the game! Good job =) @" endl ;
cout "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" endl ;
cout endl ;
} else if (lost) {
cout endl ;
cout "|||||||||||||||||||||||||||||||||||||||||||||||" endl ;
cout "|| You did not win =( Better luck next time. ||" endl ;
cout "|||||||||||||||||||||||||||||||||||||||||||||||" endl ;
cout endl ;
}return 0 ;
}int Deal() {
int face, suit, r_val, card ;do {
r_val = (rand() % 24) ;
} while (deck[r_val]) ;deck[r_val] = true ;
if (r_val 6) { suit = HEARTS ; face = r_val + 1 ; }
else if (r_val 12) { suit = CLUBS ; face = r_val - 5 ; }
else if (r_val 18) { suit = SPADES ; face = r_val - 11 ; }
else { suit = DIAMONDS ; face = r_val - 17 ; }card = (10*suit) + face ;
return card ;
}void Display(int x, int y, int z) {
int cards[3] = { x, y, z } ;
string name ;
for (int i=0; i3; i++) {
if (cards[i] != -1) { name = Card_ID(cards[i]) ; }
else { name = "-- CROWNED --" ; }
cout "\t***************************" endl ;
cout "\t Stack [" i+1 "] : " name endl ;
cout "\t***************************" endl endl ;
}
}string Card_ID(int card) {
int suit = card/10 ;
int face = card % 10 ;
string name ;if (face == 1) { name = "1" ; }
else if (face == 2) { name = "2" ; }
else if (face == 3) { name = "3" ; }
else if (face == 4) { name = "4" ; }
else if (face == 5) { name = "5" ; }
else if (face == 6) { name = "6" ; }if (suit == HEARTS) { name += " of Hearts" ; }
else if (suit == CLUBS) { name += " of Clubs" ; }
else if (suit == DIAMONDS) { name += " of Diamonds" ; }
else if (suit == SPADES) { name += " of Spades" ; }return name ;
}here's what was spit out when i tried to compile it: Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\WINDOWS\Desktop\nicole\crown.cpp" -o "C:\WINDOWS\Desktop\nicole\crown.exe" -I"C:\DEV-CPP\include\c++" -I"C:\DEV-CPP\include\c++\mingw32" -I"C:\DEV-CPP\include\c++\backward" -I"C:\DEV-CPP\include" -L"C:\DEV-CPP\lib"
C:/WINDOWS/Desktop/nicole/crown.cpp:48: parse error before `)' token
C:/WINDOWS/Desktop/nicole/crown.cpp: In function `int main()':
C:/WINDOWS/Desktop/nicole/crown.cpp:54: `string' undeclared (first use this
function)
C:/WINDOWS/Desktop/nicole/crown.cpp:54: (Each undeclared identifier is reported
only once for each function it appears in.)
C:/WINDOWS/Desktop/nicole/crown.cpp:54: parse error before `;' token
C:/WINDOWS/Desktop/nicole/crown.cpp:60: `cout' undeclared (first use this
function)
C:/WINDOWS/Desktop/nicole/crown.cpp:60: `endl' undeclared (first use thisfunction)
C:/WINDOWS/Desktop/nicole/crown.cpp:72: `name' undeclared (first use this
function)
C:/WINDOWS/Desktop/nicole/crown.cpp:72: `Card_ID' undeclared (first use this
function)
C:/WINDOWS/Desktop/nicole/crown.cpp:83: `cin' undeclared (first use thisfunction)
C:/WINDOWS/Desktop/nicole/crown.cpp: In function `void Display(int, int, int)':
C:/WINDOWS/Desktop/nicole/crown.cpp:147: parse error before `;' token
C:/WINDOWS/Desktop/nicole/crown.cpp: At global scope:
C:/WINDOWS/Desktop/nicole/crown.cpp:157: parse error before `)' token
C:/WINDOWS/Desktop/nicole/crown.cpp:159: `card' was not declared in this scope
C:/WINDOWS/Desktop/nicole/crown.cpp:160: 'string' is used as a type, but is not
defined as a type.
C:/WINDOWS/Desktop/nicole/crown.cpp:162: parse error before `if'Execution terminated
my problem is i thought it was all coded right and i really have no clue how to fix it. :/ any help would be appreciated.

Is there a place you can upload the code so that we can download and debug it? That would make it a lot easier to debug and fix the mistakes.
-Micah

There's no need to post up your code to be downloaded. It only took me 10 seconds to see that you did not include the standard namespace in your program (using namespace std;). Insert this and let me know how many of your errors go away.
P.S. Place this immediately following all of your includes in all of your files.
- Rolos

It compiles for me when I have MFC supported.
#include afx.h>
#include afxwin.h>
#include afxext.h>^those should be what you need to get MFC support which might fix your problem. You might not need all of them. Or even any....
I had to fix the main() function here:
for (int i=0; i less than 24; i++) { deck[i] = false ; }
for (int i=0; i less than 3; i++) {
card = Deal() ;
suit = card/10 ;
face = card % 10 ;
piles[i].Place(face, suit) ;
}You get a redefinition of i error. Just change that last i to something else and that'll fix that bug. Also, you might want to add in some error catching cause when the program runs and you enter in a letter it will go into an infinite loop.
-Micah

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |