I wanted to know if it is possible to use if statements to compare characters. For example, suppose I wanted to write a program to respond differently to different char inputs. I can't seem to do this using if statemtents. Here is a sample code.
Code:
#include <iostream>
using namespace std;
int main(){
char x;
cout << "Enter a character\n";
cin >> x;
cin.ignore();
if (x == y){
cout << "You entered Y.\n";
}
if (x != y ){
cout << "You didn't enter Y.\n";
}
cin.get();
return 0;
}
When I compile this it results in an error that says it is the first time the char y is declared. So my question is, how do I compare char inputs using if statments? Is there another way to do this? Yes, I'm new to this...