Math Tutor Enhanced

The Adml Tutors
Creative Commons License photo credit: AdmlCrunch

4.9: This is a modification of Chapter 3′s Problem 15, which was:

Write a program that can be used as a math tutor for a young student. The program should display two random numbers to be added, such as

+ 129

The program should then pause while the student works on the problem. When the student is ready to check the answer, he or she can press a key and the program will display the correct solution, for example:

+ 129

This time, write a program that can be used as a math tutor for a young student. The program should display two random numbers that are to be added. The program should wait for the student to enter the answer. If the answer is correct, a message of congratulations should be printed. If the answer is incorrect, a message should be printed showing the correct answer.

My solution:

/* Chapter 4 Challenge 9
   Written by Kirk Hingsberger
   October 3, 2007
   Math Tutor - Enhanced

#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;

int main()
  char ch;
  const int SEED = 999;
  int num1, num2, num3, answer;

  num1 = 1 + rand() % SEED;
  num2 = 1 + rand() % SEED;

  cout << "Enter your answer after the problem appears:" << endl;
  cout << setw(5) << num1 << endl;
  cout << "+ " << setw(3) << num2 << endl;
  cout << "_____" << endl;
  cin >> answer;
  num3 = num1 + num2;

  cout << setw(5) << num3 << " is the correct answer, ";
  if (answer == num3)
      cout << "great job!" << endl;
  else if (answer > num3)
      cout << "your answer (" << answer << ") was too high." << endl;
      cout << "your answer (" << answer << ") was too low." << endl;

  return 0;

Note: This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (4) was titled “Making Decisions”.

I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.


2 Responses to “Math Tutor Enhanced”

  1. You have a great site here. Questions.

    I’m an online student in Programming I. Are you a programmer?

    $4.95 a month for this site? And how hard was it to set up.

  2. Thanks, yep I’m a programmer. It wasn’t hard to setup, and yep Hostgator is super cheap as a host, very reliable and great value.

    Thanks again.

Leave a Reply