Good evening everyone.
I am currently working on a project to create a Math exam in C++ and i am stuck on a small part i cant seem to figure out . What i need to do is create a function in this case 'Division' that will take 2 Integers and divide them .
These integers have to be random and the numerator has to be 2 digits and numerator 1 digit , easy the problem is that the program needs to print out 10 questions but each division has to give a remainder of 0 for the division to be successful , so here is my code so far please note i am not asking for Homework help i just need a suggestion on what to do in the case 3 area and in the function called Division.
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;
int addition (int a,int b)
{
int z;
z=a+b;
return (z);
}
int multi (int a,int b)
{
int z;
z=a*b;
return (z);
}
int division (int a,int b) <---------------------------------
{
int z;
z=a/b;
return (z);
}
int substrac (int a,int b)
{
int z;
z=a-b;
return (z);
}
int main()
{
srand(time(0));
int sum,gradecounter,choice;
gradecounter=0;
cout<<setw ( 45 )<<"Algebra Exam 1"<<endl<<endl;
cout<<"Choose your exam : 1 for (+) , 2 for (-) , 3 for (/) and 4 for (x):";
cin>>choice;
switch (choice)
{
case 1 :
for (int i=1;i<=10;i++)
{
int x=(1+rand()%10);
int y=(1+rand()%10);
cout<<"How much is "<<x<<"+"<<y<<"? ";
cin>>sum;
if (sum!=addition (x,y))
cout<<"Incorect"<<endl;
else
{
gradecounter++;
cout<<"Correct"<<endl;
}
}
cout<<"your grade is:"<<gradecounter<<"/10 "<<endl;
if (gradecounter<7)
cout<<"you need extra help from your teacher";
cout<<endl;
break;
case 2:
for (int i=1;i<=10;i++)
{
int x=(10+rand()%20);
int y=(1+rand()%10);
cout<<"How much is "<<x<<"-"<<y<<"? ";
cin>>sum;
if (sum!=substrac (x,y))
cout<<"Incorect"<<endl;
else
{
gradecounter++;
cout<<"Correct"<<endl;
}
}
cout<<"your grade is:"<<gradecounter<<"/10 "<<endl;
if (gradecounter<7)
cout<<"you need extra help from your teacher";
cout<<endl;
break;
case 3: <---------------------------------
for (int i=1;i<=10;)
{
int x=(10+rand()%20);
int y=(1+rand()%10);
cout<<"How much is "<<x<<"/"<<y<<"? ";
cin>>sum;
if (sum!=division (x,y)){
cout<<"Incorect"<<endl;
}
else
{
gradecounter++;
cout<<"Correct"<<endl;
}
}
cout<<"your grade is:"<<gradecounter<<"/10 "<<endl;
if (gradecounter<7)
cout<<"you need extra help from your teacher";
cout<<endl;
break;
default :
break;
}
system ("pause");
return 0;
}
The part has an <- arrow next to em
All i need to know is how i can make 2 random numbers divided by one another gives me a remainder of 0
Thank you all