#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
string x;
cin>>x;
if(strcmp(&x.at(0), "M") == 0)
{
cout<<"midget ";
}
else if(strcmp(&x.at(0), "J") == 0)
{
cout<<"junior ";
}
else if(strcmp(&x.at(0), "S") == 0)
{
cout<<"senior ";
}
else
{
cout<<"invalid code";
}
if(strcmp(&x.at(1), "B") == 0)
{
cout<<"boys";
}
else
{
cout<<"girls";
}
return 0;
}
I've used the above code to compare MB which should return "midget boys" but it keeps falling to else and returns "invalid codeboys". Somehow the second condition works fine. My diagnostics tell me that at the first comparison it returns 66
. I guess that is the ASCII code for "M". But how do I solve my problem now?