I have a question.

I'm writing a small program in c++ for my kid to help her with maths
and to teach myself how to program. I'm using srand() to get a few random numbers for her to divide with the number she choose.

All is fine until I get something like 5/3. She is in grade 3 and will not be able to do this. How can I make sure the random number are able to go into the numbers she chooses

void Divide::doRandDivide()
{
cout << "OK. Lest see if you understand" << "\n" << endl;
srand((unsigned)time(0));
int random_int;
int lowest = 1; 
int highest = 12;
int range=(highest-lowest)+1;
int index;
int iWrong; 
int irAns;
int irTotal;
int id3Total;
int iDeel;
for(index=0;index<5;index++)
{
random_int = lowest= int(range*rand()/(RAND_MAX + 1.0));
}
irTotal = idNommer/idNommer;
cout << "How much is " << idNumber << " divided by "<< idNumber << "\n" << endl;
cin >> irAns;
if (irAns != irTotal)
{
cout << "No this is wrong "<< "\n" << endl;
iWrong++;
if (iWrong >= 3)
{
cout << "\n" << endl;
cout << "The answer is " << irTotal << endl;
}
}
 
while (irAnw != irTotal);
{
cout << "Cool " << endl;
}
 
 
for(index=0;index<5;index++)
id3Total = random_int/idNumber;
cout << "How much is " << idNommer << " divided by "<< id3Total << "\n" << endl;
cin >> irAnw;
if (irAnw != id3Total)
{
cout << "No this is wrong "<< "\n" << endl;
iWrong++;
if (iWrong >= 3)
{
cout << "\n" << endl;
cout << "The answer is " << id3Total << endl;
}
}
else
cout << "Cool " << endl;
 
while (irAnt != id3Total);{}
}

I hevent gone thru your code ... You can do something like this

Random Number % Number chosen == 0
then
proceed
else
choose other random number.

Conceptual thought: start with two numbers and multiply them together. Then you have three numbers, one of which can be evenly divided by the other two. Display them as you choose to make the divide problem.

This article has been dead for over six months. Start a new discussion instead.