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. Grade the answer and display the result
 27    if (number1 - number2 == answer)
 28      cout << "You are correct!";
 29    else
 30      cout << "Your answer is wrong." << endl << number1 << " - "
 31           << number2 << " should be " << (number1 - number2) << endl; 
 32  
 33    return 0;
 34  }