title: Generate random pupil math problems
body: <p>I try to use c++ to build a program for kids to practice their math. The problem should include addition, subtraction, multiplication, and division. These 10 problems are randomly generated. Also, Randomly generate numbers for problems. However, must ensure that both the problem and result are no longer than two digits. The problem and the result should be greater or equal to zero. The divisor cannot be zero.</p>
  
  <p>My implement is followed.</p>
  
  <pre><code>        while(prob_cout &lt; 10){
              int op = rand() % 4; // range 0-3 to match a operation
              int answer, userGuess;
              if (op == 0) { // addition
                  int number1 = rand() % 100; // problem no langer than two digits 
                  int number2 = rand() % 100;  // range 0-99 
                  answer = number1 + number2;
                  if (answer &gt;= 0 &amp;&amp; answer &lt; 100) { // valid problem: result also no more than two digits
                      prob_cout++;
                      cout &lt;&lt; number1 &lt;&lt; " + " &lt;&lt; number2 &lt;&lt; " = ";
                      cin &gt;&gt; userGuess;
                      // record problem info
                      prob_record.push_back(number1);
                      prob_record.push_back(op);
                      prob_record.push_back(number2);
                      prob_record.push_back(answer);
                      prob_record.push_back(userGuess);
                      // check answer
                      if (answer == userGuess)
                          user_scores += 10;
                      else
                          continue;
                  }
                  else
                      continue;
              }
              else if(op == 1) { // subtraction
                  int number1 = rand() % 100; // problem no langer than two digits 
                  int number2 = rand() % 100;  // range 0-99 
                  answer = number1 - number2;
                  if (answer &gt;= 0 &amp;&amp; answer &lt; 100) { // valid problem: result also no more than two digits
                      prob_cout++;
                      cout &lt;&lt; number1 &lt;&lt; " - " &lt;&lt; number2 &lt;&lt; " = ";
                      cin &gt;&gt; userGuess;
                      // record problem info
                      prob_record.push_back(number1);
                      prob_record.push_back(op);
                      prob_record.push_back(number2);
                      prob_record.push_back(answer);
                      prob_record.push_back(userGuess);
                      if (answer == userGuess)
                          user_scores += 10;
                      else
                          continue;
                  }
                  else
                      continue;
              }
              else if (op == 2) { // multiplication
                  int number1 = rand() % 20; 
                  int number2 = rand() % 20;   
                  answer = number1 * number2;
                  if (answer &gt;= 0 &amp;&amp; answer &lt; 100) { // valid problem: result also no more than two digits
                      prob_cout++;
                      cout &lt;&lt; number1 &lt;&lt; " * " &lt;&lt; number2 &lt;&lt; " = ";
                      cin &gt;&gt; userGuess;
                      // record problem info
                      prob_record.push_back(number1);
                      prob_record.push_back(op);
                      prob_record.push_back(number2);
                      prob_record.push_back(answer);
                      prob_record.push_back(userGuess);
                      // check answer
                      if (answer == userGuess)
                          user_scores += 10;
                      else
                          continue;
                  }
                  else
                      continue;
              }
              else if (op == 3) { //dividion
                  int number1 = rand() % 100; 
                  int number2 = rand() % 50; 
                  answer = number1 / number2;
                  if (answer &gt;= 0 &amp;&amp; answer &lt; 100 &amp;&amp; number1 &gt; number2) { // valid problem: result also no more than two digits
                      prob_cout++;
                      cout &lt;&lt; number1 &lt;&lt; " / " &lt;&lt; number2 &lt;&lt; " = ";
                      cin &gt;&gt; userGuess;
                      // record problem info
                      prob_record.push_back(number1);
                      prob_record.push_back(op);
                      prob_record.push_back(number2);
                      prob_record.push_back(answer);
                      prob_record.push_back(userGuess);
                      // check answer
                      if (answer == userGuess)
                          user_scores += 10;
                      else
                          continue;
                  }
                  else
                      continue;
              }
          }
  </code></pre>
  
  <p>But. I find this method can't ensure equal possiblity for these four operations. The addition and substraction are much more than multiplication and division!</p>
  
  <p>Anyone get a better idea?</p>