Problem with If statement

I am writing a program in which a single letter in form of char variable is taken from the user, then if the value is "m" then print "You r Male" otherwise "You r female"...


#include<iostream>
#include<conio.h>

using namespace std;
void main()
{
char A,M;
cout<<"Enter any single letter";
cin>>A;
if(A==M)
cout<<"You are Male";
else
cout<<"You are Female";
getch();

}]


The problem is that it gives an error that the variable 'M' is used before being initialized????How to deal with this....I mean what does it actually means???
M is a character so it cannot be used like int
if(A=='M') // see the quotes as it is single character
if you intent to use more than one character you has to use double quotes
like this
if(strcmp(A,"Male"))
If you're checking to see if the user entered the character M, check for 'M', not M.

Edit: note - this is case sensitive, so you might want to check for both 'M' and 'm', or convert the input to uppercase.
Last edited on
Topic archived. No new replies allowed.