Hmm maybe you need to look up on associative arrays HERE
But with your sparse knowledge of C++....
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
Here is a starter. I would create a structure for the two strings, then array of that structure.
#include <iostream>
using namespace std;
struct states
{
char *stname;
char *stabbr;
};
states st[] = { /* State abbreviation*/
"North Carolina", "NC",
"South Carolina", "SC",
"Georgia", "GA",
"Florida", "Fl",
"Alabama", "Al",
};
int main(int argc, char* argv[])
{
int array_size = sizeof(st) / sizeof(st[0]);
for(int i = 0; i < array_size; ++i)
{
cout << st[i].stname << "\t" << st[i].stabbr << endl;
}
return 0;
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
And along with the above code provided by Mr. Dragon, you might want to use fgets( char* my_array, SIZEOFARRAY, stdin ) to accept input from the user and a function which searches the entire structure array for the given string and then returns its state equivalent.
But personally i would advice you to go with the associative array or the STL map construct, unless you have been instructed not to do so, since it makes the code less cluttered, more logical and extensible. One thing you would never want to do in programming is to reinvent the wheel.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734