Greetings masters of coding!
I must begin by noting that I am fairly new to all of this, but I learn quickly and appreciate any advice. I am in my second quarter of C/C++ programming and I ran into this little doozy.
What seemed simple enough, I was tasked with writing a program that reads in state abbreviations and spits out the state names. No looping necessary, just a simple if, else if-type program.
I am sure that there are many ways to write this little guy, but this even stumped my professor and together we couldn't find fault in the code. I ran it on visual studio 6 and bloodshed dev, but was receiving the same output.
I even put it a cout to make sure that the characters (string) were reading into the declared variable and it was! However, the if statements were not working. I also took out the || (or) statement to simplify things and it still passes the entire run of if statements and simply prints the last else statement.
I am not requesting a different way to write it, I was hoping for knowledge as to why this would not work. On a side not, I was getting that weird auto-close thing, but I assume that is a setting in bloodshed and simply put a system("PAUSE") in there to alleviate it.
Here we go:
Many thanks for any help.Code:#include <iostream> // #include <string> I tried including this, but it didn't change things using namespace std; //State Abbreviations int main() { const int SIZE = 3; //Setting the array size char abb[SIZE]; //Get State abberviation cout<<"Enter in your state abbreviation ---->"; cin>>abb; //Begin if statement checking for the upper or lower case entry if ((abb == "NC")||(abb == "nc")) cout<< "Your state is North Carolina\n"; else if ((abb == "SC" ) || (abb == "sc")) cout<< "Your state is South Carolina\n"; else if ((abb == "GA" ) || (abb == "ga")) cout<< "Your state is Georgia\n"; else if ((abb == "FL" ) || (abb == "fl")) cout<< "Your state is Florida\n"; else if ((abb == "AL" ) || (abb == "al")) cout<< "Your state is Alabama\n"; else cout << "You have entered an incorrect value"; system ("PAUSE"); return 0; }



2Likes
LinkBack URL
About LinkBacks



