I have a 1d array of correct answers, but they are stored as upper case in the txt file. I want to take in a users input, but if he answers lower case i want the program to accept his answer as lower or upper case. am i on the right track? also, my test if its a valid response (a-d or A-D) didnt work.. is there something else i could try?
char answers[x];
cin >> user_guess;
while (user_guess != "a" || "b" || "c" || "d" || "A" || "B" || "C" || "D") //doesnt work?
{
cout<< "Please correctly identify your answer." << endl;
cin >> user_guess;
}
if (islower (user_guess) )
{
toupper (user_guess) )
}
if (user_guess != answers[x])
{
cout << "incorrect! << endl;
}
else
{
cout << "correct!" << endl;
}
Your test for a correct choice doesn’t work because that’s not how
||works. What you need is something like:Also, there’s no harm in calling
toupper()on something that isn’t a lower case character. So you can just do:If you convert
user_guessto upper case right after you read it in fromcin, then you can both shorten the “valid guess” test (by only having to test against uppercase answers), and omit thetoupper()from the test againstanswers[x].