# && in statements

• 01-25-2013
SDH
&& in statements
I am trying to write a poker hand score system. I have worked everything out except how to do full house and 2 two pair. Currently I scan through all 127 ASCII values, then if the code detects that in the input from the user it will increment a counter. But when I try to write an if statement, if the counter is equal to 3 and 2 it will not work. Any ideas why this is not working, or is there another way to do this?
here is my code to help you out, this is not my whole code as it is quite large, just the bits that i feel will help you help me. Thank you very much for your time in reading this.
Code:

```#include<stdio.h>int main(void) {  int c;     int n;     int count1[127] = {0};     int count2[127] = {0};     int count3 = {0};     int i;     int temp;     int j;     int difference;     char array[5];     char array1[5];     int picturedifference;     int difference1;     int suitdifference;     int suitcount = {0};     int count4 = {0};     n = 5;             for (c = 0; c < n; c++)         scanf("%c%c ", &array1[c], &array[c]);         getchar();           for (i = 0; i < n; i++) {         count1[array[i]]++;                    //if array[i] is N, then count1[N]++//     }                                          //these two for statement adds to the counts//     for (i = 0; i < n; i++) {         count2[array1[i]]++;}      {      for (i = 0; i < 127; i++)                          {               if ( count2[i] == 4 && suitcount!= 4 )               printf("Four of a kind. Your score is 50.\n");                             if( count2[i] == 3 && count2[i] == 2 && suitcount != 4)               printf("Full House. Your score is 25. \n");                             if ( count2[i] == 3 && suitcount != 4  )               printf("Three of a kind. Your score is 5.\n");                             if ( count2[i] == 2 && suitcount != 4  )               printf("Pair. Your score is 2.\n");                           }                                                           }       return 0;     }```
• 01-25-2013
Tclausex
Your code is confusing. You use 'count1' and 'count2' to increment the respective values in the hand, and then later you test only 'count2' and 'suitcount' which is zeroed out.

Of course count2[i] cannot be equal to 3 AND 2 at the same time which is what
Code:

`if( count2[i] ==3 && count2[i] ==2... )`
says.

You have unnecessary braces blocking your last for loop.

And you're working with the strangest deck of cards I've ever heard of if they include all 127 ASCII values, even the unprintable ones.
• 01-25-2013
SDH
sorry i tried to cut out some of code so it wasnt as long, but I will just post the whole thing so its easier for you to read.
Code:

```#include<stdio.h>int main(void) {  int c;     int n;     int count1[127] = {0};     int count2[127] = {0};     int count3 = {0};     int i;     int temp;     int j;     int difference;     char array[5];     char array1[5];     int picturedifference;     int difference1;     int suitdifference;     int suitcount = {0};     int count4 = {0};     n = 5;             for (c = 0; c < n; c++)         scanf("%c%c ", &array1[c], &array[c]);         getchar();   for(i=0;i<n;i++)       {        if ( array1[i] == '2'){               printf("Two of ");               }else if( array1[i] == '3'){               printf("Three of ");                  }else if( array1[i] == '4'){               printf("Four ");               }else if( array1[i] == '5'){               printf("Five of ");               }else if( array1[i] == '6'){               printf("Six of ");               }else if( array1[i] == '7'){               printf("Seven of ");               }else if( array1[i] == '8'){               printf("Eight of ");               }else if( array1[i] == '9'){               printf("Nine of ");               }else if( array1[i] == '0'){               printf("Ten of ");               }else if( array1[i] == 'J'){               printf("Jack of ");               }else if( array1[i] == 'Q'){               printf("Queen of ");               }else if( array1[i] == 'K'){               printf("King of ");               }else if( array1[i] == 'A'){               printf("Ace of ");}                             if ( array[i] == 'C'){               printf("Clubs\n");               }else if( array[i] == 'D'){               printf("Diamonds\n");               }else if( array[i] == 'H'){               printf("Hearts\n");               }else if( array[i] == 'S'){               printf("Spades\n");}                   }                 for (i = 0; i < n; i++) {         count1[array[i]]++;                    //if array[i] is N, then count1[N]++//     }                                          //these two for statement adds to the counts//     for (i = 0; i < n; i++) {         count2[array1[i]]++;}  //////////////////////////////////////////////////////////////////////////////// /////////////////////bubble sort///////////////////////////////////////////////        for (i=0;i<n; i++)  {     for (i=0; i<4; i++)   {       for (j=i+1; j<5; j++)       {         if(array1[i] > array1[j])         {             temp = array1[i];             array1[i] = array1[j];             array1[j] = temp;         }       }      }   }  ///////////////////////////////////////////////////////////////////////////////////////  ///////////////////////suit counter///////////////////////////////////////////////////   for(i=0;i<n-1;i++)     {     suitdifference=(array[i+1]-array[i]);       {if ( suitdifference == 0)          suitcount++;               }     } /////////////////////////////////////////////////////////////////////////////////////// ///////////////////////Picture code straight code//////////////////////////////////////   for(i=0;i<n-1;i++)     {     picturedifference=(array1[i+4]-array1[i]);             {if ( picturedifference == 33)          count4++;               }     }                 {if (suitcount == 4 && count4 == 1)                   printf("Royal Flush. Your score is 100.\n");                 } //////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// striaght code///////////////////////////////////     for(i=0;i<n-1;i++)     {     difference=(array1[i+1]-array1[i]);       {if ( difference == 1)          count3++;               }     }                                 {if ( suitcount == 4 && count3 == 4)                   printf("Straight flush. Your score is 75.\n");                   }                   {if ( suitcount != 4 && count3 == 4)                   printf("Straight. Your score is 15.\n");                   }                   {if ( suitcount != 4 && count4 == 1)                   printf("Straight. Your scoreeeee is 15.\n");                   }                   {if ( suitcount == 4 && count4 != 1 && count3 != 4 )                   printf("Flush. Your Score is 20.\n");                   }     ////////////////////////////////////////////////////////////////////////////////////     /////////////////////hand identiy codes/////////////////////////////////////////////       {      for (i = 0; i < 127; i++)                          {               if ( count2[i] == 4 && suitcount!= 4 )               printf("Four of a kind. Your score is 50.\n");                             if( count2[i] == 3 && count2[i] == 2 && suitcount != 4)               printf("Full House. Your score is 25. \n");                             if ( count2[i] == 3 && suitcount != 4  )               printf("Three of a kind. Your score is 5.\n");                             if ( count2[i] == 2 && suitcount != 4  )               printf("Pair. Your score is 2.\n");                           }                                                           }       return 0;     }```
• 01-25-2013
std10093
He didn't only say that your code is confusing. He said also about line 142 in your latest post :)
• 01-25-2013
stahta01
I suggest learning to use functions. Functions in C - Cprogramming.com
I also suggest re-reading post #2.

Tim S.