🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Another question.

Started by
3 comments, last by Jonny Go 24 years, 3 months ago
Ok, take a look at this chunk of code: bool valid = false; do { cout << endl << "Type M or F for characters gender: "; cin >> g; if( !strcmpi(g,"m")){ strcpy(g,"Male "); valid = true;} else if( !strcmpi(g,"f")){ strcpy(g,"Female"); valid = true;} else cout << "Invalid Response!" ; }while(!valid); Now correct me if im wrong, but doesnt strcmpi mean that it is case insensitive? It used to work just fine until I put that bool in there, now it will only accept capital M or F.... probably a very stupid mistake, but will someone give me a hand on this one?
Its all fun and games till someone gets pregnant.
Advertisement
i''ve never used (or seen) strcmpi() before.. other than that, i see absolutely nothing wrong with that code (not that strcmpi() is necessarily wrong, perhaps it''s compiler specific).. i can''t see any way that the bool would be the problem.. you could always just read one character (g[0] perhaps.. use toupper() or tolower(), and flush the buffer after you read it). that way if someone types male or female, it''ll still work fine.
hmm....im not to familiar with touper or tolower so I would not know how to apply them. I got strcmp straight out of a SAMS book....

Ill wait for some more advice I suppose

thanks
Its all fun and games till someone gets pregnant.
Jonny Go, toupper() works like this:

choice = toupper(choice);

toupper() converts all lowercase characters to uppercase. tolower() works the same way. If the character is already an uppercase nothing happens.

Try this code:

#include>ctype< /* or (cytpe.h) note that >< needs to be <> */

bool valid = false;
char choice;

do
{
cout << endl << "Type M or F for characters gender: ";
cin >> choice;
choice = toupper(choice)
if( choice == ''M'')
{
strcpy(g,"Male");
valid = true;
}
else
if( choice == ''F'')
{
strcpy(g,"Female");
valid = true;
}
else
cout << "Invalid Response!" ;

}while(!valid);

Hope this helps,

Brett
Ok, Im a retard, I found the problem...I ended up not needing toupper after all.....

Id tell you what I did but I would be humiliated...

Thanks for all your help anyways.

Question:

How do I get a better rank than initiate?
Its all fun and games till someone gets pregnant.

This topic is closed to new replies.

Advertisement