Im having problems with my input validation. Its not working correctly. Keeps repeating the validation loop even when i enter something that should be correct. basically im trying to make it so that the only valid answer is either uppercase or lower case letters a-d.
#include <iostream>
using namespace std;
int main()
{
const int SIZE = 20;
char correctAnswers[SIZE] = {'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A',};
char Answers[SIZE];
bool arraysEqual = true;
int index = 0;
int numMissed = 0;
int numCorrect = 0;
cout << "Please enter an A, B, C, or D for the answer given to: " << endl;
for (index = 0; index < SIZE; index++)
{
cout << "question " << (index + 1) << ": ";
cin >> Answers[index];
while (Answers[index] != 'A' || Answers[index] != 'B' || Answers[index] != 'C' || Answers[index] != 'D' || Answers[index] != 'a' || Answers[index] != 'b' || Answers[index] != 'c' || Answers[index] != 'd')
{
cout << "Please enter a valid answer : ";
cin >> Answers[index];
}
}
for(index = 0; index< SIZE; index++)
{
if (correctAnswers[index] != Answers[index])
{
cout << "You missed question # " << (index + 1) << endl;
}
else
numCorrect++;
}
numMissed = SIZE - numCorrect;
if(numCorrect >= 15)
cout << "This student passed the driving exam!!!" << endl;
else cout << "The student failed the driving exam. DO NOT UNDER ANY CIRCUMSTANCES GIVE THEM A LICENSE." << endl;
cout << "The student got " << numCorrect << " answers correct on the test!" << endl;
cout << "the student got " << numMissed << " answers wrong on the test!" << endl;
system("pause");
return(0);
}