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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
using namespace std;
//void welcome();
//void splash();
void add(int&, int&, int&, int&, int&);
void multiply(int&, int&, int&, int&, int&);
void int_div(int&, int&, int&, int&, int&);
void Modulus(int&, int&, int&, int&, int&);
void exit(int&, int&);
int main()
{
int option, num1, num2, userAnswer, correct, incorrect;
//using constants to make code easier to read
const int ADD = 1, MULTIPLY = 2, INT_DIV = 3, MODULUS = 4, EXIT = 5;
unsigned int seed = time(NULL);
correct = incorrect = 0;
srand(seed);
//function call
//splash();
//welcome();
//do while loop allows user to continuously input any number they would like
//until they enter 5.
do
{
num1 = 1 + rand() % 10;
num2 = 1 + rand() % 10;
system("CLS");
cout << down5;
cout << over4 << "Basic Math" << endl;
cout << over4 << "----------" << endl;
cout << over4 << "1. Addition" << endl;
cout << over4 << "2. Multiplication" << endl;
cout << over4 << "3. Integer Division" << endl;
cout << over4 << "4. Modulus" << endl;
cout << over4 << "5. Exit" << endl;
cout << over4 << "Option: ";
cin >> option;
cout << "\n\n";
if (option == ADD)
{
add(num1, num2, correct, incorrect, userAnswer);
}
else if (option == MULTIPLY)
{
multiply(num1, num2, correct, incorrect, userAnswer);
}
else if (option == INT_DIV)
{
int_div(num1, num2, correct, incorrect, userAnswer);
}
else if (option == MODULUS)
{
Modulus(num1, num2, correct, incorrect, userAnswer);
}
else if (option == EXIT)
{
exit(correct, incorrect);
/*cout << over4 << "Correct\tIncorrect" << endl
<< over4 << "-------\t---------" << endl
<< over4 << setw(4) << correct << "\t"
<< setw(5) << incorrect << endl; */
}
else
{
cout << over4 << option << " is not a valid menu item." << endl;
}
cout << down5;
system("PAUSE");
} while (option != EXIT); //once 5 is entered the loop breaks and the system closes
cin.get();
}
void add(int &num1, int &num2, int &userAnswer, int &correct, int &incorrect)
{
cout << over4 << "Addition" << endl << endl;
cout << over4 << num1 << " + " << num2 << " = ";
cin >> userAnswer;
if(userAnswer == num1 + num2)
{
cout << over4 << "Correct!" << endl;
correct++;
cout << over4 << "Correct " << correct << endl;
}
else
{
cout << over3 << "Incorrect. The correct answer is "
<< num1 + num2 << endl;
incorrect++;
cout << over4 << "Incorrect " << incorrect << endl;
}
}
void multiply(int &num1, int &num2, int &userAnswer, int &correct, int &incorrect)
{
cout << over4 << "Multiplication" << endl;
cout << over4 << num1 << " * " << num2 << " = ";
cin >> userAnswer;
if(userAnswer == num1 * num2)
{
cout << over4 << "Correct!" << endl;
correct++;
cout << over4 << "Correct " << correct << endl;
}
else
{
cout << over3 << "Incorrect. The correct answer is "
<< num1 * num2 << endl;
incorrect++;
cout << over4 << "Incorrect " << incorrect << endl;
}
}
void int_div (int &num1, int &num2, int &userAnswer, int &correct, int &incorrect)
{
cout << over4 << "Integer Division" << endl;
cout << over4 << num1 << " / " << num2 << " = ";
cin >> userAnswer;
if(userAnswer == num1 / num2)
{
cout << over4 << "Correct!" << endl;
correct++;
cout << over4 << "Correct " << correct << endl;
}
else
{
cout << over3 << "Incorrect. The correct answer is "
<< num1 / num2 << endl;
incorrect++;
cout << over4 << "Incorrect " << incorrect << endl;
}
}
void Modulus(int &num1, int &num2, int &userAnswer, int &correct, int &incorrect)
{
cout << over4 << "Modulus" << endl;
cout << over4 << num1 << " % " << num2 << " = ";
cin >> userAnswer;
if(userAnswer == num1 % num2)
{
cout << over4 << "Correct!" << endl;
correct++;
cout << over4 << "Correct " << correct << endl;
}
else
{
cout << over3 << "Incorrect. The correct answer is "
<< num1 % num2 << endl;
incorrect++;
cout << over4 << "Incorrect " << incorrect << endl;
}
}
void exit(int &correct, int &incorrect)
{
cout << over4 << "Correct\tIncorrect" << endl
<< over4 << "-------\t---------" << endl
<< over4 << setw(4) << correct << "\t"
<< setw(5) << incorrect << endl;
}
|