#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std; // prototype and name space declaration
bool testAnswer(int, int, int);
void correctOutput();
void incorrectOutput();
bool mathTest();
//------------------------------------------------------------------
//------------------------------------------------------------------
//------------------------------------------------------------------
int main()
{
if (mathTest())
{
!(mathTest());
mathTest();
}
}
bool mathTest() //main function
{
srand((unsigned)time(0)); // random number generator
int random_integerA, random_integerB;
int input;
for(int index=1; index<=2; index++){
if (index == 1)
{
random_integerA = (rand()%10);
}
else
{
random_integerB = (rand()%10);
}
}
cout << random_integerA ;
cout << " * ";
cout << random_integerB ;
cout << " is: ";
cin >> input;
if (testAnswer(random_integerA, random_integerB, input))
{
correctOutput();
}
else
incorrectOutput();
while(testAnswer(random_integerA, random_integerB, input) != true)
{
cout << random_integerA ;
cout << " * ";
cout << random_integerB ;
cout << " is: ";
cin >> input;
if (testAnswer(random_integerA, random_integerB, input))
{
correctOutput();
return true;
mathTest();
break;
}
else
incorrectOutput();
}}
//------------------------------------------------------------------
//------------------------------------------------------------------
//------------------------------------------------------------------
bool testAnswer(int numA, int numB, int inputNum) //
{
if ( numA * numB == inputNum)
return true;
else
return false;
}
//------------------------------------------------------------------
//------------------------------------------------------------------
//------------------------------------------------------------------
void correctOutput() // display correct output
void incorrectOutput() // display incorrect output
1) a simple math multiplication program, that will generate two random number and ask the user to input a correct result.
2) current output
1 * 3 = 3(user input)
correct move on
4 * 4 = 16(user input)
correct move on
1 *0 = 0 (user input)
correct
end of program
3) i need the program to continue to prompt the question everytime the input is correct
4) i don't know why it stop after i enter 3 correct answer, i am expecting it run forever