title: How to score yahtzee in c++
body: <p>I am writing a yahtzee game for my c++ programming class.  One of my difficulties I have ran into is the scoring system for different categories.  I think I have figured out how to do it for adding 1s, 2s etc but I do not know how to have the program determine when a 3 of a kind, 4 of a kind, etc has been rolled.  Here is my code so far.</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      //Declare variables
      int players;
      int turn = 1;
      vector&lt;string&gt; names;
      string playerName;
      int dice[5];
      int finalScore = 0;
      char reroll[5];
      char rollDice;
      int tries = 1;
      const int DICE = 5;
      int roll[DICE];
      int scorecard;
      int scoreThisTurn(int scorecard);
      int turnScore = 0;
  
      //Introduction, get number of players.
      cout &lt;&lt; "Hello, welcome to Yahtzee!  How many players are there?" &lt;&lt; endl;
      cin &gt;&gt; players;
  
      if (players &gt; 4) {
          cout &lt;&lt; "Sorry, the maximum number of players is 4." &lt;&lt; endl;
          cout &lt;&lt; "How many players are there?" &lt;&lt; endl;
          cin &gt;&gt; players;
      }
  
      //Get player names
      string getNames();
      for (int i = 0; i &lt; players; i++)  {
          cout &lt;&lt; "Hello player " &lt;&lt; i + 1 &lt;&lt; ", please enter your name" &lt;&lt; endl;
          cin &gt;&gt; playerName;
              names.push_back(playerName);
          }
  
      srand(time(NULL));  //random seed
  
      cout &lt;&lt; "Welcome to Yahtzee!\n";
  
      while (turn &lt;= 13) {       //roll dice
          cout &lt;&lt; "Press 'r' to roll" &lt;&lt; endl;
          cin &gt;&gt; rollDice;
          if (rollDice == 'r') {
              for (int i = 0; i &lt; DICE; i++) {
                  roll[i] = rand() % 6 + 1;
              }
          }
          cout &lt;&lt; "You rolled: " &lt;&lt; roll[0] &lt;&lt; ", " &lt;&lt; roll[1] &lt;&lt; ", " &lt;&lt;
              roll[2] &lt;&lt; ", " &lt;&lt; roll[3] &lt;&lt; ", " &lt;&lt; roll[4] &lt;&lt; endl;
          cout &lt;&lt; "Type y to reroll or n to keep.  For example yynnn would keep the first three dice" &lt;&lt; endl;
          cin &gt;&gt; reroll[0] &gt;&gt; reroll[1] &gt;&gt; reroll[2] &gt;&gt; reroll[3] &gt;&gt; reroll[4];
  
          for (int i = 0; i &lt; DICE; i++) {
              if (reroll[i] == 'y') {
                  roll[i] = rand() % 6 + 1;
              }
              else if (reroll[i] == 'n') {
                  roll[i];
              }
              else cout &lt;&lt; "Sorry you entered an invalid letter." &lt;&lt; endl;
          }
  
          cout &lt;&lt; "Your second roll is: " &lt;&lt; roll[0] &lt;&lt; ", " &lt;&lt; roll[1] &lt;&lt; ", " &lt;&lt;
              roll[2] &lt;&lt; ", " &lt;&lt; roll[3] &lt;&lt; ", " &lt;&lt; roll[4] &lt;&lt; endl;
  
          cout &lt;&lt; "Type y to reroll or n to keep.  For example yynnn would keep the first three dice" &lt;&lt; endl;
          cin &gt;&gt; reroll[0] &gt;&gt; reroll[1] &gt;&gt; reroll[2] &gt;&gt; reroll[3] &gt;&gt; reroll[4];
  
          for (int i = 0; i &lt; DICE; i++) {
              if (reroll[i] == 'y') {
                  roll[i] = rand() % 6 + 1;
              }
              else if (reroll[i] == 'n') {
                  roll[i];
              }
              else cout &lt;&lt; "Sorry you entered an invalid letter." &lt;&lt; endl;
          }
  
          cout &lt;&lt; "Your third roll is: " &lt;&lt; roll[0] &lt;&lt; ", " &lt;&lt; roll[1] &lt;&lt; ", " &lt;&lt;
              roll[2] &lt;&lt; ", " &lt;&lt; roll[3] &lt;&lt; ", " &lt;&lt; roll[4] &lt;&lt; endl;
  
          //displays scorecard categories
          cout &lt;&lt; "Which category would you like to score this in" &lt;&lt; endl;
          cout &lt;&lt; "1 - ones: " &lt;&lt; endl;
          cout &lt;&lt; "2 - twos: " &lt;&lt; endl;
          cout &lt;&lt; "3 - threes: " &lt;&lt; endl;
          cout &lt;&lt; "4 - fours: " &lt;&lt; endl;
          cout &lt;&lt; "5 - fives: " &lt;&lt; endl;
          cout &lt;&lt; "6 - sixes: " &lt;&lt; endl;
          cout &lt;&lt; "7 - 3 of a kind: " &lt;&lt; endl;
          cout &lt;&lt; "8 - 4 of a kind: " &lt;&lt; endl;
          cout &lt;&lt; "9 - small straight: " &lt;&lt; endl;
          cout &lt;&lt; "10 - large straight: " &lt;&lt; endl;
          cout &lt;&lt; "11 - full house: " &lt;&lt; endl;
          cout &lt;&lt; "12 - yahtzee: " &lt;&lt; endl;
          cout &lt;&lt; "13 - chance: " &lt;&lt; endl;
  
          //asks player to choose where to score
          cout &lt;&lt; "\nEnter 1-14 to choose a category." &lt;&lt; endl;
          cin &gt;&gt; scorecard;
  
          //assigns points
          for (int i = 0; i &lt; DICE; i++) {
              turnScore = 0;
              if (scorecard == 1) {
                  if (roll[i] == 1) {
                      turnScore = turnScore + 1;
                  }
              }
              if (scorecard == 2) {
                  if (roll[i] == 2) {
                      turnScore = turnScore + 2;
                  }
              }
              if (scorecard == 3) {
                  if (roll[i] == 3) {
                      turnScore = turnScore + 3;
                  }
              }
              if (scorecard == 4) {
                  if (roll[i] == 4) {
                      turnScore = turnScore + 4;
                  }
              }
              if (scorecard == 5) {
                  if (roll[i] == 5) {
                      turnScore = turnScore + 5;
                  }
              }
              if (scorecard == 6) {
                  if (roll[i] == 6) {
                      turnScore = turnScore + 6;
                  }
                  if (scorecard == 7) {
                      if (roll[i] == 2) {
                          turnScore = turnScore + 2;
                      }
                  }
  
          }
  
          cout &lt;&lt; scorecard &lt;&lt; endl;
  
          turn++;
      }
  
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>As you can see I've set up the scoring for the first 6 categories but don't know how to proceed.</p>