Accepting Upper and Lowercase - else/if

I am trying to write a program that displays the tax rate for a couple of different states and I need the program to accept the users input of either "FL" or "fl" for example. I am very new to C++; just started this semester so please don't spare any details. I think I might have the upper or lowercase code down but the problem that I am having is that no matter what I enter, so long as it meets the parameters of 2 characters, it prints the first else/if statement.

int main(int argc, char *argv[])
{
string state;

splash();
welcome();
system("CLS");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n";
cout << "\t\t\tEnter a state abbreviation: ";
cin >> state;

system("CLS");
cout << "\n\n\n\n\n\n\n\n\n\n";
if (state.length() != 2)
{
cout << "\t\tSorry, please restart the program and enter an abbreviation\n";
cout << "\t\tthat is 2 characters.";
}
else if (state == "FL" || "fl")
{
cout << "\t\t \"" << state << "\" is Florida so the taxrate is 7.5%";
}
else if (state == "RI" || "ri")
{
cout << "\t\t \"" << state << "\" is Rhode Island so the taxrate is 7.0%";
}
else if (state == "MD" || "md")
{
cout << "\t\t\t\"" << state << "\" is Maryland so the taxrate is 6.0%";
}
else if (state == "OR" || "or")
{
cout << "\t\t\t\"" << state << "\" is Oregon so the taxrate is 0.0%\n";
cout << "\t\t\tReally, Oregon has no sales tax! Go ahead, look it up!";
}
else
{
cout << "\t\t\t\"" << state << "\" is UNKNOWN so the default taxrate is 10.0%";
}


cout << "\n\n\n\n\n\t\t\t";
system("PAUSE");
return EXIT_SUCCESS;
}
Last edited on
else if (state == "FL" || "fl")
In place of that, you'd have
else if (state == "FL" || state == "fl")

...and the same goes for the others. :)

Does this help?

-Albatross
Last edited on
I started to put that in there and never did it. That solved the everything. Thank you very much Albatross!
You can make it even easier. See the second code snippet I posted here for how to select on a string
http://www.cplusplus.com/forum/general/11460/#msg54095

Even if you want to stick with the if else if ... construct, it would be both simpler and more bulletproof to transform the user's input to upper-case or something...
Topic archived. No new replies allowed.