Assigning int values a name
In my source code, I have an int Gender written. I need to associate entering 1 as being a male and 2 as being a female. How is this done?
You can use if statements to differentiate between male and female.
Ex.
1 2 3 4 5 6 7 8
|
if(Gender == 1){
std::cout << "Male\n";
}
else if(Gender == 2){
std::cout << "Female\n";
}
else
std::cout << "Undefined\n";
|
Use an enumerator.
1 2 3 4 5 6 7 8 9 10
|
enum { MALE = 1, FEMALE };
if (iChoice == MALE)
{
std::cout << "Male.\n";
}
else if (iChoice == FEMALE)
{
std::cout << "Female.\n";
}
|
Topic archived. No new replies allowed.