Greetings C++ Lovers:

I'm a student very new to this C++. Yes I took Linux & UNIX. That was a year ago and I've never applied it to ANYTHING. If it's not too much trouble, I'm at a loss. A Big LOSS. You see, the reason I say this is bcuz. I took the initiative to go to my instructor to try to understand these C++ fundamentals.......and guess what.......It was still like reading this..."hjgddwufweuifdhweuf"! YEA!!! He tried breaking it down for me, now that I'm here (AT HOME) trying to figure this out I'm lost and DON'T KNOW WHAT I'm DOING :mad:

I've been given an assignment to write a program that asks the user to enter one of the following state abbreviations NC, SC, GA, FL, or AL. This program should display the name of the state that corresponds with the abbrev. Entered. Can you please help me? PLEASE? This IS frustrating. AM I to start out like this?....

char STATE[5];            /*   State abbreviation*/
{"North Carolina", "NC"},
{"South Carolina", "SC"}, 
{"Georgia", "GA"}, 
{"Florida", "Fl"},
{"Alabama", "Al"},
};
cout<<endl <<endl;

Please forgive for my ignorance to this course.

Your assistance means a whole lot!:sad:

Sincerely,

AnG’

Hmm maybe you need to look up on associative arrays HERE
But with your sparse knowledge of C++....

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;
}

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.

I will try that. Thank you so much. And you are correct. When it comes to C++, I am "dense" in this region. I truely thank you for your time though. I was sincerely considering withdrawing from this class, but due to some compassionate collaborators, I'm liberated!


Yours Truely,

AnG'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.