I don't understand

Hello all.

So I'm working on an assignment and I'm having trouble as to why my code doesn't seem to be working.

I'm trying to have the user input values (which go into an array). I need to make sure that the user input is only 1 of 4 characters(A,B,C or D). When I see if the input is A it works, but as soon as I set the if statement to see if it is A or B it always sets it to false.

Below is my code, any help would be amazing!

Thank you all.

// Assignment5.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <iomanip>
#include <string>


using namespace std;



int main()
{
char correctAnswers[10] { 'B','D','A','A','C','A','B','A','C','D' };
char studentAnswers[10];
int y = 0;

for (int x = 0; x < 10; x++)
{

cout << "Please enter your answer for question " << x + 1 << "." << endl;
cin >> studentAnswers[x];

if ((studentAnswers[x] != 'A')||(studentAnswers[x]!='B'))
{
cout << "Only A,B,C or D are accepted answers." << endl;
y = y + 1;
x = x - 1;
}

else

{
cout << "Else." << endl;
}

while (y >= 3)
{
cout << "Good Bye" << endl;
return 0;
}
}


for (int z = 0; z < 10; z++)
{
cout << studentAnswers[z] << endl;
}

return 0;
}
Last edited on
Holy crap!

Sorry, I figured it out....


if ((studentAnswers[x] != 'A')&&(studentAnswers[x]!='B'))

:)
Topic archived. No new replies allowed.