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
|
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
using namespace std;
/* -----------------------------------------------------------------------------
FUNCTION: addition()
DESCRIPTION: Runs Addition Practice problems
RETURNS: ...
NOTES: n/a
----------------------------------------------------------------------------- */
void addition(int num1, int num2,int number_correct,int A,int B, int C,
int D, int correct_answer, int d_level,int number_wrong,
char given_answer, int attempts, int question_num)
{
correct_answer = 0;
num1 = 0;
num2 = 0;
number_correct = 0;
A = 0;
B = 0;
C = 0;
D = 0;
system("cls");
cout << " ------------------------------------------------------" << endl
<< " ARITHMETIC PRACTICE PROGRAM" << endl
<< " ADDITION MENU" << endl
<< " ------------------------------------------------------" << endl;
cout << endl << endl;
do
{
switch (d_level)
{
case 1:
num1 = 1 + rand() % 9;
num2 = 1 + rand() % 9;
A = 1 + rand() % 17;
B = 1 + rand() % 17;
C = 1 + rand() % 17;
D = 1 + rand() % 17;
cout << " What is" << endl//Questions
<< " " << num1 << endl
<< " +" << num2 << endl
<< " _______________" << endl;
cout << endl << endl;
correct_answer = num1 + num2;
possible_answers(num1, num2, A, B, C, D);
cin >> given_answer;
user_answer(given_answer, correct_answer,
A, B, C, D, attempts, number_correct,
number_wrong, question_num);
}
}while (attempts <= 3 && question_num == 10);
}
void possible_answers(int num1, int num2, int A, int B, int C, int D)
{
cout << " A. " << num1 << " + " << num2 << " = " << A << endl;//Anwsers
cout << " B. " << num1 << " + " << num2 << " = " << B << endl;
cout << " C. " << num1 << " + " << num2 << " = " << C << endl;
cout << " D. " << num1 << " + " << num2 << " = " << D << endl;
cout << " E. None of the above" << endl;
}
void user_answer(char given_answer, int correct_answer,
int A, int B, int C, int D, int attempts, int number_correct,
int number_wrong, int question_num)
{
switch (given_answer)
{
case 'A':
case 'a':
if (given_answer == correct_answer && given_answer == A)
cout << "Correct" << question_num++
<< number_correct++;
else if (given_answer != correct_answer && given_answer == A)
cout << "Wrong" << attempts++
<< number_wrong;
break;
case 'B':
case 'b':
if (given_answer == correct_answer && given_answer == B)
cout << "Correct";
else if (given_answer != correct_answer && given_answer == B)
cout << "Wrong";
break;
case 'C':
case 'c':
if (given_answer == correct_answer && given_answer == C)
cout << "Correct";
else if (given_answer != correct_answer && given_answer == C)
cout << "Wrong";
break;
case 'D':
case 'd':
if (given_answer == correct_answer && given_answer == D)
cout << "Correct";
else if (given_answer != correct_answer && given_answer == D)
cout << "Wrong";
break;
case 'E':
case 'e':
if (given_answer != A ||
given_answer != B ||
given_answer != C ||
given_answer != D)
cout << "Correct";
else if (given_answer == A ||
given_answer == B ||
given_answer == C ||
given_answer == D)
cout << "Wrong";
break;
default:
cout << "Please enter vaild choice";
break;
}
}
string get_time()
{
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
// printf("The current date/time is: %s", asctime(timeinfo));
string timestamp(asctime(timeinfo));
return timestamp;
}
|