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);


}

switch the ors (||) to ands (&&). All of the conditions need to be true to proceed. You can decrease the number of conditionals by using toupper() to change any lower case to upper case and then just check for those.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.