//Adrian Lazaro CSC5 Chapter 4, P. 221, #9
//
/*****************************************************************************
*
* COMPUTE TWO RANDOM NUMBERS
* __________________________________________________________________________
* This program gives the user a random math problem to solve. if solved
* correctly user will be congratulated if wrong program shows right answer.
*
* Computation is based on formula:
* outputAnswer = num1 + num2
* __________________________________________________________________________
* INPUT
* num1 : First random number
* num2 : Second random number
*
* OUTPUT
* Depending on random numbers
*
****************************************************************************/
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
unsigned seed = time(0);
//Declare variables
int num1;
int num2;
int inputAnswer;
int outputAnswer;
srand(seed); //Creates random number
num1 = 1 + rand() % 999; //Assigns random number 1-999 to num1
num2 = 1 + rand() % 999; //Assigns randim number 1-999 to num2
outputAnswer = num1 + num2; //CALCULATION
//Display's math problem
cout << num1 << endl;
cout << num2 << endl;
cin >> inputAnswer; //User answer to problem
//OUTPUT
if (inputAnswer == outputAnswer)
{
cout << "\nCongratulations you got the right answer!";
}
else
{
cout << "\nWrong answer, the correct answer is " << outputAnswer;
}
return 0;
}