```
#include <iostream>
#include <ctime>
using namespace std;
class Fraction
{
private:
int Num;
int Denom;
public:
void Reduce(); //will reduce the fraction to lowest terms
void AddFraction(); //will add the two fractions together
void print(); //will print the fraction in the form: numerator / denominator
};
void Reduce(int &Num, int &Denom, int &Num2, int &Denom2)
/* This function is called after ReadFraction(). This function will
reduce the two fractions.
Pre: Two Fractions
Post: Two reduced fractions */
{
int a, b, c, d, i, j = 0;
a = Denom;
b = Num;
c = Denom2;
d = Num2;
for (i = a * b; i > 1; i--)
{
if ((a % i == 0) && (b % i == 0))
{
a /= i;
b /= i;
}
}
for (j = 50; j > 1; j--)
{
if ((c % j == 0) && (d % j == 0))
{
c /= j;
d /= j;
}
}
Denom = a;
Num = b;
Denom2 = c;
Num2 = d;
}
void Reduce(int &Num, int &Denom)
/* This function is called from AddFraction(). The fraction added in
AddFraction() is reduced here.
Pre: One fraction added from two
Post: A reduced fraction */
{
int a = 0;
int b = 0;
int i = 0;
a = Denom;
b = Num;
for (i = 50; i > 1; i--)
{
if ((a % i == 0) && (b % i == 0))
{
a /= i;
b /= i;
}
}
Denom = a;
Num = b;
}
void print(int &Num, int &Denom)
/* This function displays the reduced and added fraction. This
function is called after AddFraction()
Post: Prints fraction */
{
cout << "The reduced and added fraction is " << Num << "/" << Denom << endl;
}
int main ()
{
int numbers[3];
int answer; // USER INPUT
srand (time(0)); // ONLY NEEDS TO BE SEEDED ONCE
// NO NEED FOR A COUNTER IN WHILE LOOPS
//Initiate checking for correct answer
while (answer != -1) // WHILE USER HASN'T ENTERED -1
{
numbers[0] = rand() % 9 + 1; // load the first random number into numbers[0]
numbers[1] = rand() % 9 + 1; // load the second into numbers[1]
numbers[2] = numbers[0] * numbers[1]; // load the answer into numbers[2]
cout << "\n\n""What is " << numbers[0] << "*" << numbers[1] << "?" << endl;
cin >> answer;
if (answer == numbers[0] * numbers[1]) // check against the numbers array
{
cout << "\n""Correct!"<< endl; //Outcome for correct answer
}
else //statement for while loop
// GIVE THE CORRECT ANSWER AN MOVE ON
cout << "\nWrong! The correct answer was " << numbers[2] << endl; //Outcome for incorrect answer
}
return 0;
}
```