1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std ;
void menu (int& replay);
bool isCorrect (int& studentAnswer , int answer);
void addition (int num1 , int num2 , char op);
void subtraction (int num1 , int num2, char op);
void multiplication (int num1 , int num2, char op);
void division (int num1 , int num2, char op);
int main ()
{
int choice , n1 , n2 ;
int op = rand()%4;
char operatorChar;
srand(time(NULL));
n1 = ((rand() % 10) +1);
n2 = ((rand() % 10) +1);
menu (choice);
for(int i=0; i<10; i++)
// Repeat the questions 10 times
{
do
{
switch(op)
{
case 0:
operatorChar = '-';
subtraction ( n1 , n2 , operatorChar);
break;
case 1:
operatorChar = '+';
addition ( n1 , n2 , operatorChar);
break;
case 2:
operatorChar = '*';
multiplication ( n1 , n2 , operatorChar);
break;
case 3:
operatorChar = '/';
division ( n1 , n2 , operatorChar);
break;
}
} while (choice!=2) ;
}
cout << " The End Of The Program ." <<endl;
return 0;
}
void menu (int& replay)
{
cout << "Welcome To The easiest Math Tutor!" << endl << endl;
cout << "This simple program designed to help you practice ," << endl;
cout << "addition, subtraction, multiplication, and division" << endl << endl;
cout << "To start:" << endl << endl;
cout << "Please enter 1 , to Quit enter 2 : " << endl;
cout << "\t\t\t\t\t";
cin >> replay;
}
bool isCorrect (int& studentAnswer , int answer)
{
return studentAnswer == answer;
}
void addition (int num1 , int num2 , char op)
{
int studentAnswer, answer;
srand(time (0));
num1 = ((rand() % 10) +1);
num2 = ((rand() % 10) +1);
cout << "How much is" << " "<< num1 <<" " << operatorChar << " "<< num2 << "?" << endl;
cin >> studentAnswer;
answer=num1+num2;
do
{
cin>> studentAnswer;
if (studentAnswer != answer)
cout <<"No, please try again !"<<endl;
cin >> answer;
} while (studentAnswer != answer);
if (isCorrect(studentAanswer , Answer)
cout<< "Very Good !" <<endl;
}
void subtraction (int num1 , int num2 , char op)
{
int studentAnswer, answer;
srand(time (0));
num1 = ((rand() % 10) +1);
num2 = ((rand() % 10) +1);
cout << "How much is" << " "<< num1 <<" " << operatorChar << " "<< num2 << "?" << endl;
cin >> studentAnswer;
answer=num1-num2;
do
{
cin>> studentAnswer;
if (studentAnswer != answer)
cout<< "No, please try again !" <<endl;
cin << answer;
} while (studentAnswer != answer);
if (isCorrect(studentAanswer , Answer)
cout<< "Very Good !" <<endl;
}
void multiplication (int num1 , int num2 , char op)
{
int studentAnswer, answer;
srand(time (0));
num1 = ((rand() % 10) +1);
num2 = ((rand() % 10) +1);
cout << "How much is" << " "<< num1 <<" " << operatorChar << " "<< num2 << "?" << endl;
cin >> studentAnswer;
answer=num1*num2;
do
{
cin>> studentAnswer;
if (studentAnswer != answer)
cout<< "No, please try again !" <<endl;
cin << answer;
} while (studentAnswer != answer);
if (isCorrect(studentAanswer , Answer)
cout<< "Very Good !" <<endl;
}
void division (int num1 , int num2 , char op)
{
int studentAnswer, answer;
srand(time (0));
num1= ((rand() % 10) +1);
num2= ((rand() % 10) +1);
cout << "How much is" << " "<< num1 <<" " << operatorChar << " "<< num2 << "?" << endl;
cin >> studentAnswer;
answer = num1 / num2;
do
{
cin>> studentAnswer;
if (studentAnswer != answer)
cout<< "No, please try again !" <<endl;
cin << answer;
} while (studentAnswer != answer);
if(isCorrect(studentAanswer , Answer)
cout<< "Very Good !" <<endl;
}
|