Introduction to Programming with C++, Y. Daniel Liang
Output
Variable Name     Value in Memory
number1
number2
answer
temp
  1  #include <iostream>
  2  #include <ctime> // for time function
  3  #include <cstdlib> // for rand and srand functions
  4  using namespace std;
  5  
  6  int main()
  7  {
  8    // 1. Generate two random single-digit integers
  9    srand(time(0));
 10    int number1 = rand() % 10;
 11    int number2 = rand() % 10;
 12  
 13    // 2. If number1 < number2, swap number1 with number2
 14    if (number1 < number2)
 15    {
 16      int temp = number1;
 17      number1 = number2;
 18      number2 = temp;
 19    }
 20  
 21    // 3. Prompt the student to answer "What is number1 - number2"
 22    cout << "What is " << number1 << " - " << number2 << "? ";
 23    int answer;
 24    cin >> answer;
 25  
 26    // 4. Repeatedly ask the user the question until it is correct
 27    while (number1 - number2 != answer) 
 28    {
 29      cout << "Wrong answer. Try again. What is "
 30        << number1 << " - " << number2 << "? "; 
 31      cin >> answer;
 32    }
 33  
 34    cout << "You got it!" << endl;
 35  
 36    return 0;
 37  }