Thread: simple problem(cept for newbie)

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    34

    simple problem(cept for newbie)

    I am modifying a deal function to deal the cards to 4 players and then print them out. It is all written but all 4 players get the same cards...Any help would be apprecieated

    Code:
    void dealdeck(Card *deckptr , Card handsDealt [4][5])
    {
     int i;
     
      for(i=0;i<5;i++)
      {
    	  handsDealt[1][i].faceValue = faces[deckptr[i].faceValue]; 
    	  handsDealt[1][i].suitValue = deckptr[i].suitValue;
    	  handsDealt[2][i].faceValue = faces[deckptr[i].faceValue]; 
    	  handsDealt[2][i].suitValue = deckptr[i].suitValue;
    	  handsDealt[3][i].faceValue = faces[deckptr[i].faceValue]; 
    	  handsDealt[3][i].suitValue = deckptr[i].suitValue;
    	  handsDealt[4][i].faceValue = faces[deckptr[i].faceValue]; 
    	  handsDealt[4][i].suitValue = deckptr[i].suitValue;
      }
      printf("\nPlayer One's Cards...\n");
       for(i=0;i<5;i++)
       {
    printf("%c of %c, ",handsDealt[1][i].faceValue, handsDealt[1][i].suitValue);
       }
         printf("\nPlayer Two's Cards...\n");
       for(i=0;i<5;i++)
       {
    printf("%c of %c, ",handsDealt[2][i].faceValue, handsDealt[2][i].suitValue);
       }
         printf("\nPlayer Three's Cards...\n");
       for(i=0;i<5;i++)
       {
    printf("%c of %c, ",handsDealt[3][i].faceValue, handsDealt[3][i].suitValue);
       }
         printf("\nPlayer Four's Cards...\n");
       for(i=0;i<5;i++)
       {
    printf("%c of %c, ",handsDealt[4][i].faceValue, handsDealt[4][i].suitValue);
       }printf("\n\n\n\n");
    }
    Output:
    Code:
    Player One's Cards...
    Q of ♥, 5 of ♥, 4 of ♥, A of ♣, 6 of ♥,
    Player Two's Cards...
    Q of ♥, 5 of ♥, 4 of ♥, A of ♣, 6 of ♥,
    Player Three's Cards...
    Q of ♥, 5 of ♥, 4 of ♥, A of ♣, 6 of ♥,
    Player Four's Cards...
    Q of ♥, 5 of ♥, 4 of ♥, A of ♣, 6 of ♥,

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    In your for loop, you're setting them to be the same. Without knowing more about the dealing algorithm, there's not much I can suggest. Oh, and you're going out of the array boundaries by using [1] for the first player. It should be [0] for the first one.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    Taking a stab in the dark as to the rest of your code, but from what is visible, it's pretty obvious why they're all getting the same hand dealt...
    Code:
      for(i=0;i<5;i++)
      {
    	  handsDealt[1][i][i].faceValue = faces[deckptr[i].faceValue]; 
    	  handsDealt[1][i].suitValue =  deckptr[i].suitValue;
    	  handsDealt[2][i].faceValue =  faces[deckptr[i].faceValue]; 
    	  handsDealt[2][i].suitValue = deckptr[i].suitValue;
    	  handsDealt[3][i].faceValue = faces[deckptr[i].faceValue]; 
    	  handsDealt[3][i].suitValue = deckptr[i].suitValue;
    	  handsDealt[4][i].faceValue = faces[deckptr[i].faceValue]; 
    	  handsDealt[4][i].suitValue = deckptr.suitValue;
      }

    I've marked in read what you should be looking at. They're being reused repeatedly without incrementing the counter. Perhaps you should nest another For loop which would represent the handsDealt array (represented as h for this example), then use deckptr[(i*h)+h].

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM