| | |
C++ Help....plez.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 8
Reputation:
Solved Threads: 0
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?....
Please forgive for my ignorance to this course.
Your assistance means a whole lot!
Sincerely,
AnG’
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;
Your assistance means a whole lot!
Sincerely,
AnG’
Last edited by ~s.o.s~; Oct 21st, 2006 at 3:16 pm.
Hmm maybe you need to look up on associative arrays HERE
But with your sparse knowledge of C++....
But with your sparse knowledge of C++....
I don't accept change; I don't deserve to live.
Here is a starter. I would create a structure for the two strings, then array of that structure.
C++ Syntax (Toggle Plain Text)
#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
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.
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 don't accept change; I don't deserve to live.
![]() |
Similar Threads
- Problem on array based list (C)
- Not able to send email by "MAIL" (OS X)
- JAM Computers(Review) (Website Reviews)
- ~2 Requests~ (Graphics and Multimedia)
- newbie... Java load large picture :) Lit'l help plez (Java)
Other Threads in the C++ Forum
- Previous Thread: What is the Command-Line Argument for???
- Next Thread: Need help with some syntax errors
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






