Input Validation Strings

Hello all,

I am trying to check user input, the program will only accept 4 answers, A, B, C and D. I planned on using a do-while, but i can't get the validation working. Here is my code:

1
2
3
4
5
6
7
8
9
10
	for (counter = 0; counter < SIZE; counter++)
	{
		do
		{
			cout << "Please input students answers for question " << 
					(counter + 1) << ".";
			cin >> stuAns[counter];
		}while(strcmp(stuAns[counter], "A") != 0 || strcmp(stuAns[counter], "B") != 0
			|| strcmp(stuAns[counter], "C") != 0 || strcmp(stuAns[counter], "D") != 0);
	}

I am using Borland C++ 5.5.1 with jGRASP as my text editor. The code will compile as it stands. Could any tell me the error? Thanks in advance.
Last edited on
The while logic should be AND && not OR ||

1
2
3
4
5
6
do
	{
	    cout << "Please input students answers for question " << (counter + 1) << ".";
	   cin >> stuAns[counter];
	}while(strcmp(stuAns[counter], "A") != 0 && strcmp(stuAns[counter], "B") != 0 
                        && strcmp(stuAns[counter], "C") != 0 && strcmp(stuAns[counter], "D") != 0);
Last edited on
Thanks a bunch guestgulkan. I tried the && and everything works thanks again.
Topic archived. No new replies allowed.