does any one know how to get the RNG to generate multiple choices for a problem and have the RNG also decide which of the choices is the correct one for problem.
int num1;
int num2;
int A;
int B;
int C;
int D;
int correct_answer = 0;
num1 = 0;
num2 = 0;
number_correct = 0;
A = 0;
B = 0;
C = 0;
D = 0;
num1 = 1 + rand() % 9;
num2 = 1 + rand() % 9;
A = 1 + rand() % 17;
B = 1 + rand() % 17;
C = 1 + rand() % 17;
D = 1 + rand() % 17;
A != B, C, D;
B != A, C, D;
C != A, B, D;
D != A, B, C;
cout << num1 << endl
<< "+" << num2 << endl;
cout << endl << endl;
correct_answer = num1 + num2;
cout << "A." << num1 << " + " << num2 << " = " << A << endl;
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;
cin >> given_answer;
do
{
attempts = 0;
question_num = 0;
switch (given_answer)
{
case'A':
case'a':
if (given_answer == correct_answer && given_answer == A)
cout << "Correct"
<< system("pause")
<< number_correct++
<< question_num++;
elseif (given_answer != correct_answer && given_answer == A)
cout << "Wrong"
<< system("pause")
<< number_wrong++
<< attempts++;
break;
case'B':
case'b':
if (given_answer == correct_answer && given_answer == B)
cout << "Correct"
<< system("pause")
<< number_correct++
<< question_num++;
elseif (given_answer != correct_answer && given_answer == B)
cout << "Wrong"
<< system("pause")
<< number_wrong++
<< attempts++;
break;
case'C':
case'c':
if (given_answer == correct_answer && given_answer == C)
cout << "Correct"
<< system("pause")
<< number_correct++
<< question_num++;
elseif (given_answer != correct_answer && given_answer == C)
cout << "Wrong"
<< system("pause")
<< number_wrong++
<< attempts++;
break;
case'D':
case'd':
if (given_answer == correct_answer && given_answer == D)
cout << "Correct"
<< system("pause")
<< number_correct++
<< question_num++;
elseif (given_answer != correct_answer && given_answer == D)
cout << "Wrong"
<< system("pause")
<< number_wrong++
<< attempts++;
break;
case'E':
case'e':
if (given_answer != A ||
given_answer != B ||
given_answer != C ||
given_answer != D)
cout << "Correct"
<< system("pause")
<< number_correct++
<< question_num++;
elseif (given_answer == A ||
given_answer == B ||
given_answer == C ||
given_answer == D)
cout << "Wrong"
<< system("pause")
<< number_wrong++
<< attempts++;
break;
default:
cout << "Please enter vaild choice";
break;
}
} while (attempts <= 3 || question_num == 10);
}
I have this code within a loop that will give the user 3 chances to get the question right before it will cout that they got the question wrong and then keep asking questions for a total of 10 questions.
Am I on the right track or can someone explain to me what I did wrong.
I also wanted to state that I did seed the RNG in this code.