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
|
#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#define over2 "\t\t"
#define over3 "\t\t\t"
#define over4 "\t\t\t\t"
#define down5 "\n\n\n\n\n"
#define down7 "\n\n\n\n\n\n\n"
#define down8 "\n\n\n\n\n\n\n\n"
#define down10 "\n\n\n\n\n\n\n\n\n\n"
#define down11 "\n\n\n\n\n\n\n\n\n\n\n"
using namespace std;
//declare two global variables for count.
int gNum_Correct;
int gNum_Incorrect;
int gRandom1, gRandom2, gCorrAnswer, gResponse;
int totalAnswered;
char choice,sign;
//prototypes
void menu();
void menuError();
void equation(int,int,int,char,string);
void results(int,int,int,int);
void summary();
int main()
{
unsigned seed = time(0);
srand (seed);
gRandom1 = 1 + rand() % (10); //catch a number from 1 to 10
gRandom2 = 1 + rand() % (10); //catch a number from 1 to 10
/* splash();
welcome();*/
menu();
cin >> choice;
menuError();
cout << showpoint << setprecision(2) << fixed;
switch (choice)
{
case 'A':
case 'a':
equation(gRandom1, gRandom2, gRandom1 + gRandom2, '+', "Addition");
break;
case 'B':
case 'b':
equation(gRandom1, gRandom2, gRandom1 - gRandom2, '-', "Subtraction");
break;
case 'C':
case 'c':
equation (gRandom1, gRandom2, gRandom1 * gRandom2, '*', "Multiplication");
break;
case 'D':
case 'd':
equation (gRandom1, gRandom2, gRandom1 / gRandom2, '/', "Integer Division");
break;
case 'E':
case 'e':
equation (gRandom1, gRandom2, gRandom1 % gRandom2, '%', "Modulus");
break;
case 'F':
case 'f':
case 'X':
case 'x':
system ("CLS");
cout << down10
<< over3 << "\n\n\t\t\tYou have decided to end the "
<< "program.\n" << endl;
cout << down10;
break;
}
summary();
return EXIT_SUCCESS;
}
void equation(int gRandom1,int gRandom2,int gCorrAnswer,char sign,string equationType)
{
system ("CLS");
cout << down11
<< over4 << " " << equationType << "\n" << endl
<< over4 << " " << gRandom1 << "" << endl
<< over4 << " " << sign << " " << gRandom2 << endl
<< over3 << " -------------- \n" << endl
<< over3 << "Please enter your answer. " << endl;
cin >> gResponse;
cout << down8;
results();
}
void results(int gRandom1,int gRandom2,int gCorrAnswer,int gResponse)
{
if (gRandom1 + gRandom2 == gCorrAnswer && gRandom1 + gRandom2 == gResponse)
{
cout << down11 << over3 << "You are correct!!" << endl;
}
else if (gRandom1 - gRandom2 == gCorrAnswer && gRandom1 - gRandom2 == gResponse)
{
cout << down11 << over3 << "You are correct!!" << endl;
}
else if (gRandom1 * gRandom2 == gCorrAnswer && gRandom1 * gRandom2 == gResponse)
{
cout << down11 << over3 << "You are correct!!" << endl;
}
else if (gRandom1 / gRandom2 == gCorrAnswer && gRandom1 / gRandom2 == gResponse)
{
cout << down11 << over3 << "You are correct!!" << endl;
}
else if (gRandom1 % gRandom2 == gCorrAnswer && gRandom1 % gRandom2 == gResponse)
{
cout << down11 << over3 << "You are correct !!" << endl;
}
else
{
cout << down11 << over3 << "You are incorrect!!" << endl;
}
}
void summary()
{
system ("CLS");
cout << down11
<< over3 << " Summary() was called!!\n" << endl
<< over2 << "The following global variables will be displayed: \n" << endl
<< over3 << " Total number correct: " << gNum_Correct << endl
<< over3 << " Total number incorrect: " << gNum_Incorrect << endl
<< over3 << " Your average is: " << endl
<< down8;
system ("CLS");
}
void menu()//input from user
{
system ("CLS");
cout << down5
<< over3 << " Welcome to Math Practice" << endl
<< over3 << " ------------------------ " << endl
<< over2 << " Please choose a selection that corresponds with" << endl
<< over2 << " the type ofproblem you would like to solve.\n " << endl
<< over4 << " A. Addition" << endl
<< over4 << " B. Subtraction " << endl
<< over4 << " C. Multiplication " << endl
<< over4 << " D. Integer Division " << endl
<< over4 << " E. Modulus " << endl
<< over4 << " F. Exit the program \n" << endl
<< over3 << " Please ENTER your selection here ";
cin >> choice;
}
void menuError()
{
system ("CLS");
cout << down11
<< over3 << "You have chosen an invalid option." << endl
<< over3 << "Your choices are A,B,C,D,E, and F." << endl
<< over3 << "Please try again." << endl
<< down11;
}
|