#include <iostream> 
using namespace std; 
#include <cstdlib> 
#include <ctime> 
  
int additionProblem(int topNumber, int bottomNumber) 
{ 
  int result = 0; // 0 is the code for incorrect 
  
  int userAnswer; 
  cout << "\n\n\n      " << topNumber << " + " << bottomNumber << " = "; 
  cin >> userAnswer; 
  cin.ignore(1000, 10); 
  
  int theAnswer = topNumber + bottomNumber; 
  if (theAnswer == userAnswer) 
  { 
    cout << "      Correct!" << endl; 
    result = 1; // 1 is the code for correct 
  } // if 
  else 
    cout << "      Very good, but a better answer is " << theAnswer << endl; 
  
  return result; 
} // additionProblem
int main() 
{ 
  srand(time(0)); // first statement in main, executed only once! 
  
  int score = 0; 
  score += additionProblem(rand() % 10, rand() % 10); 
  score += additionProblem(rand() % 10, rand() % 10); 
  score += additionProblem(rand() % 10, rand() % 10); 
  score += additionProblem(rand() % 10, rand() % 10); 
  score += additionProblem(rand() % 10, rand() % 10); 
  
  cout << "\n      TOTAL SCORE: " << score << " out of 5" << endl; 
} // main 
