Thread: Few errors I can't figure out

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    4

    Few errors I can't figure out

    I'm a newbie at c++ so I'm sure you will find lots of mistakes but I get 3 erroros when compiling this that I can't figure out.

    Code:
    //******************************************/
    // Poker Game
    // Play Poker 
    // Programmer: burn
    // 
    //******************************************/
    #include<iostream>
    
    using std::cout;
    using std::cin;
    using std::ios;
    using std::endl;
    
    #include <cstdlib>
    #include <ctime>
    
    #include <iomanip>
    
    // ********Function Prototypes ********
    
    int findPair( int[][2] );        
    
    int find2Pair( int[][2] ); 
    
    int findThree( int[][2] );
    
    int findFour( int[][2] );
    
    int findFullHouse( int[][2] );
    
    int findFlush( int[][2]);
    
    int findStraight( int[][2] );
    
    int findStraighFlush( int[][2] );
    
    int findRoyalFlush( int[][2] );
    
    int playHands (int[][2]); 
    
    void printResults (int, int);
    
    void shuffle( int [][ 13 ] );
    
    void deal5( const int [][ 13 ], const char *[], const char *[], int[][2] , int );
    
    void initializeDeck( int[][ 13 ] );
    
    int main()
    {
    	int handarray[5][2];
    	int handarray2[5][2];
    	int startCard = 1;
    
       const char *suit[ 4 ] =  
          { "Hearts", "Diamonds", "Clubs", "Spades" };
       const char *face[ 13 ] = 
          { "Ace", "Deuce", "Three", "Four",
            "Five", "Six", "Seven", "Eight",
            "Nine", "Ten", "Jack", "Queen", "King" };
        int deck[ 4 ][ 13 ] = { 0 };
    
    	int player1Score = 0,
    		player2Score = 0;
    
    	srand( time( 0 ) ); 
    
    	shuffle(deck);
    	
    	player1Score = playHands ( handarray );  //  puts playhands valuie in player1score 
    
    	player2Score = playHands ( handarray2 );    // Puts playHands value in player2Score
    
    	printResults (player1Score, player2Score );	// Prints winner
    
    
    	return 0;
    
    
    }
    
    
    // ********Playhands function********
    
    int playHands ( handarray ) {
    
    	int score = 0;
    
    	score = findRoyalFlush(handarray[][]);		  // Looks for royal and puts value in score
    
    	if(score == 0 ) {
    		score = findStraightFlush(handarray[][]);   // Looks for striaght puts value in score
    	}
    
    	if(score == 0 ) {
    		score = findFour(handarray[][]);		 	  // Looks for four of a kind puts value in score
    	}
    
    	if(score == 0) {
    		score = findFullHouse(handarray[][]);		  // Looks for a full house puts value in score
    	}
    
    	if(score == 0) {
    		score = findFlush(handarray[][]);			  // Looks for a flush puts value in score
    	}
    
    	if(score == 0) {
    		score = findStriaght(handarray[][]);		  // Looks for a striaght puts value in score
    	}
    
    	if(score == 0) {
    		score = findThree(handarray[][]);			  // Looks for three of a kind puts value in score
    	}
    
    	if(score == 0) {
    		score = find2Pair(handarray[][]);			  // Looks for two pair puts value in score
    	}
    
    	if(score == 0) {
    		score = findPair(handarray[][]);			  // Looks for a pairputs value in score
    	}
    
    	return score; 
    
    }
    
    
    // ******* printResults Function ********
    
    void printResults (int player1Score, int player2Score) {
    
    	if ( player1Score > player2Score ){
    		cout << "player1 wins" << endl;
    	}
    
    	if ( player2Score > player1Score ){
    		cout << "player2 wins" << endl; 
    	}
    
    	return 0; 
    }

    errors

    Compiling...
    poker.cpp
    d:\junk\poker.cpp(85) : error C2065: 'handarray' : undeclared identifier
    d:\junk\poker.cpp(85) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
    d:\junk\poker.cpp(140) : error C2562: 'printResults' : 'void' function returning a value
    d:\junk\poker.cpp(41) : see declaration of 'printResults'
    Error executing cl.exe.

    poker.obj - 3 error(s), 0 warning(s)

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    317
    Remove the return 0 statement from the printresults function.

    Declare handarray outside of any function(make it global).

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    4
    That fixed the printresults problem.

    handarray is already global

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    317
    Good point, my bad. The function definition should have the same arguments as the functio declaration:

    int playHands ( handarray ) {

    should be:

    int playHands(int [][2]){

    hope this helps.

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    4
    hmm I'm sure something is all screwed. After changing this
    int playHands ( playHands ) {

    to this

    int playHands ( int[][2] ) {

    all of these

    score = findRoyalFlush(handarray[][])

    had errors so I chaned them like so

    score = findRoyalFlush(handarray)

    they all look like that now inside the playhands function which got me down to 1 error


    D:\junk\poker.cpp(91) : error C2065: 'handarray' : undeclared identifier

    It points to this

    if(score == 0) {
    score = findRoyalFlush(handarray);
    }

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    317
    Alright in the function prototype use this:

    int playHands( ar[][2]);

    Then on the header for the function declaration:

    int playHands( ar[][2]){

    then on the individual function calls:

    score = findRoyalFlush(ar);

    Sorry looks like we kindof came almost full circle, but it should work.

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    317
    Their were some spelling errors which cause some problems, here is the code that works:
    Code:
    #include<iostream>
    
    using std::cout;
    using std::cin;
    using std::ios;
    using std::endl;
    
    #include <cstdlib>
    #include <ctime>
    
    #include <iomanip>
    
    // ********Function Prototypes ********
    
    int findPair( int[][2] );        
    
    int find2Pair( int[][2] ); 
    
    int findThree( int[][2] );
    
    int findFour( int[][2] );
    
    int findFullHouse( int[][2] );
    
    int findFlush( int[][2]);
    
    int findStraight( int[][2] );
    
    int findStraightFlush( int[][2] );
    
    int findRoyalFlush( int[][2] );
    
    int playHands (int ar[][2]); 
    
    void printResults (int, int);
    
    void shuffle( int [][ 13 ] );
    
    void deal5( const int [][ 13 ], const char *[], const char *[], int[][2] , int );
    
    void initializeDeck( int[][ 13 ] );
    
    int main()
    {
    	int handarray[5][2];
    	int handarray2[5][2];
    	int startCard = 1;
    
       const char *suit[ 4 ] =  
          { "Hearts", "Diamonds", "Clubs", "Spades" };
       const char *face[ 13 ] = 
          { "Ace", "Deuce", "Three", "Four",
            "Five", "Six", "Seven", "Eight",
            "Nine", "Ten", "Jack", "Queen", "King" };
        int deck[ 4 ][ 13 ] = { 0 };
    
    	int player1Score = 0,
    		player2Score = 0;
    
    	srand( time( 0 ) ); 
    
    	shuffle(deck);
    	
    	player1Score = playHands ( handarray );  //  puts playhands valuie in player1score 
    
    	player2Score = playHands ( handarray2 );    // Puts playHands value in player2Score
    
    	printResults (player1Score, player2Score );	// Prints winner
    
    
    	return 0;
    
    
    }
    
    
    // ********Playhands function********
    
    int playHands ( int ar[][2] ) {
    
    	int score = 0;
    
    	score = findRoyalFlush( ar);		  // Looks for royal and puts value in score
    
    	if(score == 0 ) {
    		score = findStraightFlush(ar);   // Looks for striaght puts value in score
    	}
    
    	if(score == 0 ) {
    		score = findFour(ar);		 	  // Looks for four of a kind puts value in score
    	}
    
    	if(score == 0) {
    		score = findFullHouse(ar);		  // Looks for a full house puts value in score
    	}
    
    	if(score == 0) {
    		score = findFlush(ar);			  // Looks for a flush puts value in score
    	}
    
    	if(score == 0) {
    		score = findStraight(ar);		  // Looks for a striaght puts value in score
    	}
    
    	if(score == 0) {
    		score = findThree(ar);			  // Looks for three of a kind puts value in score
    	}
    
    	if(score == 0) {
    		score = find2Pair(ar);			  // Looks for two pair puts value in score
    	}
    
    	if(score == 0) {
    		score = findPair(ar);			  // Looks for a pairputs value in score
    	}
    
    	return score; 
    
    }
    
    
    // ******* printResults Function ********
    
    void printResults (int player1Score, int player2Score) {
    
    	if ( player1Score > player2Score ){
    		cout << "player1 wins" << endl;
    	}
    
    	if ( player2Score > player1Score ){
    		cout << "player2 wins" << endl; 
    	}
     
    }

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    4
    Thanks I knew there was something I must have missed. Know its time to work on all these functions.

    Thanks again.

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    317
    No prob. Good luck and post if you need help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 12:28 AM
  3. Visual C++
    By gvector1 in forum Windows Programming
    Replies: 20
    Last Post: 03-14-2003, 11:37 AM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM