Note that there are some explanatory texts on larger screens.

plurals
  1. POPoker code cleanup modification from book...not quite right
    primarykey
    data
    text
    <p>Working through more book examples- this one is a partial poker program- This segment deals with straight hand....</p> <p>First what was given- only relevant parts....will provide entire code if needed...</p> <pre><code>int suits[5]; //index 1..4- value start at 1 int values[14]; //index 1..13- value same as rank, A = 1, K = 13 cin.get(rankCh); switch (toUpper(rankCh)) { case 'A': values = 1; break; case '2': values = 2; break; case '3': values = 3; break; case '4': values = 4; break; case '5': values = 5; break; case '6': values = 6; break; case '7': values = 7; break; case '8': values = 8; break; case '9': values = 9; break; case 'T': values = 10; break; case 'J': values = 11; break; case 'Q': values = 12; break; case 'K': values = 13; break; default: badCard = true; } </code></pre> <p>Other functions:</p> <pre><code>bool isFlush(int suits[]) { for(i = 1; i &lt;= 4; i++) if (suits[i] == 5) //5 here is Number of Cards return true; return false; } </code></pre> <p>Yeah, I know about the array declarations but that is how it is defined- nice justification for it in the text...starting to number at 1 I want my straight hand to handle both Ace high and low- right now as define above aces are low...</p> <p>Two versions: 1st appears not sure correct with low aces...</p> <p>CODE</p> <pre><code>bool isStraight(int values[]) //Version one only straight- low aces only { int count = 0; for (i = 1; i &lt;= 13; i++) { if (values[i] != 1) { count++; } else count = 0; if (count == 5) //5 is NUMCARDS return true; } return false; } </code></pre> <p>Now this is the where I need some recommendation: to have a function to handle both ace high and low:</p> <pre><code>bool isStraight(int values[]) //Version handles both high and low { int count = 0; for (i = 1; i &lt;= 13; i++) { if (values[i] != 1) { count++; // if(i == 1 &amp;&amp; values[1] != 0) //Check for high and low // count++; } else count = 0; if (count == 5) //5 is NUMCARDS return true; } return false; } </code></pre> <p>Would what I have in comments work to handle both ace high and low...</p> <p>Since i = 1 is represented as ace and not sure what values[1] is correct should it be values[13] or what...maybe something like</p> <pre><code>if (i == 1) values[13] //not sure... </code></pre> <p>Recommendations- </p> <ul> <li>do not want wholesale changes- just to have minor changes with what I have...I do not want to sort or solve by brute force i.e like values[1] == 1 &amp;&amp; values [2] ==1 you get the point- the text does that already but I am trying to rewrite it this way...</li> </ul> <p>Thanks...Hope I am getting across my modification I would like...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload