Hello,
I've written a simple program, which asks the user to respond to a YES or NO question using the character Y/y for YES and the character N/n for NO. The foundation of this program is based around several IF statements implemented to aid in finding the ASCII value of the character entered before invoking the corresponding cout statement that informs the user which character they entered.
My Question: How should a program be written to deal with ignoring case sensitivity in regards to the users' input?
Here is my amateurish attempt,
Code:
#include <iostream>
using namespace std;
int main()
{
/*program inquires a yes or no response from the user,
in this case, using the characters "Y/y" and "N/n".*/
cout << "Do you like programming (Y/y for YES, N/n for NO): ";
char user_input;
cin >> user_input;
/*The following are IF statements written for the program to determine whether the user answered YES or NO.
The program then performs the cout statement that contains the corresponding character to the ASCII value found.*/
if(user_input == 121 || user_input == 89)
{
if(user_input == 121)
{
cout << "\nYou answered YES with the lowercase 'y'." << endl;
return 0;
}
else if(user_input == 89)
{
cout << "\nYou answered YES with the UPPERCASE 'Y'." << endl;
return 0;
}
return 0;
}
else if(user_input == 110 || user_input == 78)
{
if(user_input == 110)
{
cout << "\nYou answered NO with the lowercase 'n'." << endl;
return 0;
}
else if (user_input == 78)
{
cout << "\nYou answered NO with the UPPERCASE 'N'." << endl;
return 0;
}
return 0;
}
return 0;
}