hello,

I am attempting to prompt a user for an importance level, and ask them
to enter Low, Med, or High. When they enter their input, I would like
to check it to make sure it is one of the 3; if not I plan to loop
back and prompt them again. Problem is I cannot get the statement
right that tests the input. It works for 'High', and it works for 'Low
' and 'Med '; but I cannot get it to work for 'Med' and 'Low' (no
space after). I tried eliminating the space in the compare function,
but to no avail. What am I doing wrong here? 

...

cout << "Enter the ugency level (Low, Med, or High): " << endl;
getline(cin, urgency);
urgency.resize(4); //to make record size static
//VALIDATION
for (int i = 0;  i < urgency.size(); i++)
        urgency[i] = toupper(urgency[i]);
        
if (urgency.compare("HIGH") != 0 && urgency.compare("MED ") != 0 &&
        urgency.compare("LOW ") != 0){
        cout << "The urgency level you entered does not match any of the
possible entries" << endl;

        ...

p.s. I know I could move the resize to after the compare test and the
code would work fine, but as I am trying to learn this language, I get
the feeling that I am missing something about how either the compare
function or the string variable work, so I figured I would ask the
question.

Thanks in advance,

Nim



Reply via email to