#include <iostream> 
using namespace std; 
#include <cstdlib> 
#include <ctime> 
  
bool additionProblem(int topNumber, int bottomNumber) 
{ 
  bool result = false; // assume answer will be wrong 
  
  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 = true; // answer is right! 
  } // if 
  else 
    cout << "      Very good, but a better answer is " << theAnswer << endl; 
  
  return result; 
} // additionProblem 
  
int main() 
{ 
  srand(time(0)); 
  
  int score = 0; 
  if (additionProblem(rand() % 10, rand() % 10)) score++; 
  if (additionProblem(rand() % 10, rand() % 10)) score++; 
  if (additionProblem(rand() % 10, rand() % 10)) score++; 
  if (additionProblem(rand() % 10, rand() % 10)) score++; 
  if (additionProblem(rand() % 10, rand() % 10)) score++; 
  
  cout << "\n      TOTAL SCORE: " << score << " out of 5" << endl; 
} // main 
