Hi,
I am a beginner C++ programmer and I am trying to code in a way that makes it so that if the name provided is an empty string, then the response would be "You must enter a valid name". But my if statement is not working properly because even if the code is not an empty string, it is still saying "You must enter a valid name". Please help me.
Here is a snippet of the code.
insert
Code:
int main()
{
string donorName;
string donorGender;
int donorWeight;
int donorHeight;
int donorAge;
cout << "What is the donor's name?" << endl;
cin.ignore(INT_MAX, '\n');
getline(cin, donorName);
cout << "What is the donor's gender?" << endl;
cin >> donorGender;
cout << "What is the donor's age?" << endl;
cin >> donorAge;
cout << "What is the donor's weight(in pounds)?" << endl;
cin >> donorWeight;
cout << "What is the donor's height?" << endl;
cin >> donorHeight;
if (donorName == "")
{
cout << " --- You must enter a valid name." << endl;
return (-1);
}
else if (donorGender != "Male" && donorGender != "Female" && donorGender != "Trans Male" && donorGender != "Trans Female" && donorGender != "Queer" && donorGender != "Different")
{
cout << "--- You must enter a valid gender." << endl;
}