title: Cows and Bulls Game - C++
body: <p>Question - Implement a guessing game called Cows and Bulls. Cows represents the amount of correct guesses. Bulls represent the amount of correct guesses in the right position. For instance, the computer has 1234 and the user guesses 2135 the result being: 1 Bull and 3 Cows. </p>
  
  <p>I have written the code but I keep getting 0 Bulls and 0 Cows. I have played about with it for over an hour and still cannot seem to find the problem. This version was done with characters instead of numbers but the same rules apply.</p>
  
  <pre><code>#include "std_lib.h";
  
  vector&lt;char&gt; letters;
  vector&lt;char&gt; answers;
  
  void defineletters() {
  
    letters.push_back('a');
    letters.push_back('b');
    letters.push_back('c');
    letters.push_back('d');
  }
  
  int testcows(char a) {
  
    int manycows = 0;
  
    for (int i = 0; i &lt; letters.size(); ++i) {
      if (a == letters[i]) {
        ++manycows;
      }
    }
  
    return manycows;
  }
  
  int testposition() {
  
    int manybulls = 0;
  
    for (int i = 0; i &lt; letters.size(); ++i) {
      if (answers[i] == letters[i]) {
        ++manybulls;
      }
    }
  
    return manybulls;
  }
  
  int main() {
  
    int cows = 0;
  
    char answer1;
    char answer2;
    char answer3;
    char answer4;
  
    cin &gt;&gt; answer1 &gt;&gt; answer2 &gt;&gt; answer3 &gt;&gt; answer4;
    answers.push_back(answer1);
    answers.push_back(answer2);
    answers.push_back(answer3);
    answers.push_back(answer4);
  
    cows = testcows(answer1) + testcows(answer2) + testcows(answer3) +
           testcows(answer4);
  
    cout &lt;&lt; testposition() &lt;&lt; "Bulls\n" &lt;&lt; cows - testposition()
         &lt;&lt; "Cows\n";
  
    keep_window_open("-");
  }
  </code></pre>