I am writing a program that asks the user for their gender. I know that atoi converts arrays into integers, but I need the input from the user in the form of F or M into a char, and return it to the main function to be displayed at the end of the program.
string Employee::getgender(char gen)
{
cout << "Please enter your Gender: " << endl;
//atoi function would go here, what for char?
getline(cin,gen)
return gen;
}
#include <string>
#include <iostream>
std::string getgender(char gen)
{
if (gen == 'f' || gen == 'F')
return"Female";
elseif (gen == 'm' || gen == 'M')
return"Male";
elsereturn"Sorry, but your selection does not fit our definition of a gender";
}
int main(void)
{
char gender;
std::cout << "Please enter your gender (m/f): ";
std::cin >> gender;
std::cout << getgender(gender) << "\n";
}