| | |
State abbreviations
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 1
Reputation:
Solved Threads: 0
C++ Help Please!!!!!!!!!!!
The Question is:
Write a program that asks a user to enter one of the following state abbreviations: NC, SC, GA, FL, or AL. The program should then display the name of the state that cooresponds with the abbreviation entered ( North Carolina, South Carolina, Georgia, Florida, or Alabama).
Input Validation: Accept abbreviations with both letters in uppercase or both in lowercase. Display an error message if an abbreviation other than what is listed is entered.
THANK YOU VERY MUCH!!!!!!!!!!!
The Question is:
Write a program that asks a user to enter one of the following state abbreviations: NC, SC, GA, FL, or AL. The program should then display the name of the state that cooresponds with the abbreviation entered ( North Carolina, South Carolina, Georgia, Florida, or Alabama).
Input Validation: Accept abbreviations with both letters in uppercase or both in lowercase. Display an error message if an abbreviation other than what is listed is entered.
THANK YOU VERY MUCH!!!!!!!!!!!
Well, we don't blatantly do homework questions here. Show some effort and help us to help you. How far into this program have you gotten so far? Have you prompted the user to enter a state abbreviation? Have you done an error check to make sure the abbreviation entered was valid? What technique are you using to correspond a state abbreviation with a full state? Are you printing the full state name out to the screen?
*hint hint hint*
*hint hint hint* Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
•
•
Join Date: Sep 2004
Posts: 27
Reputation:
Solved Threads: 0
Hi,
We can help you by giving a pseudocode for ur programme
input : TWO Characters
OutPut: State Name
The aslgo goes like this
Ask the user to enter two chracters
store the characters in lets say variable ch,
now check if the input is valid or not by an if statement giving right parameters
if the input do not have right parameters i-e it is input is not valid , ask the user to give input again or simply quit the programme showing an error message
if the input is valid use if-else statements to show out put
e.g
*******************************************
if(ch=='NC' || ch == 'nc' )
cout<<"North Carolina\n";
else if(ch=='SC' || ch =='sc' )
cout<<"South Carolina\n";
else.......................
*******************************************
I hope this would help u , if still there are some ambiguities , feel free to ask again,,,but do try it by ur own b4 asking next question.....
Fahad
We can help you by giving a pseudocode for ur programme
input : TWO Characters
OutPut: State Name
The aslgo goes like this
Ask the user to enter two chracters
store the characters in lets say variable ch,
now check if the input is valid or not by an if statement giving right parameters
if the input do not have right parameters i-e it is input is not valid , ask the user to give input again or simply quit the programme showing an error message
if the input is valid use if-else statements to show out put
e.g
*******************************************
if(ch=='NC' || ch == 'nc' )
cout<<"North Carolina\n";
else if(ch=='SC' || ch =='sc' )
cout<<"South Carolina\n";
else.......................
*******************************************
I hope this would help u , if still there are some ambiguities , feel free to ask again,,,but do try it by ur own b4 asking next question.....
Fahad
•
•
•
•
Originally Posted by Narue
>now check if the input is valid or not by an if statement giving right parameters
This is okay if the OP is forced to use such a braindead approach. Otherwise a series of 50 if statements is silly, and a table driven approach is far better.
how to use the table driven you mention above? can u teach me?
>actually i also will use if else.
Your loss. Have fun typing all of that.
>how to use the table driven you mention above?
The best part is that the table can be filled from a file, thus keeping the code very short and easy to follow as opposed to your 50 if statements. And if the USA decides to grow, which is probable, you would have to figure out where to change your code, modify it, and then test it to make sure you didn't make a mistake I would only have to add a single quick entry to my input file.
Your loss. Have fun typing all of that.
>how to use the table driven you mention above?
C++ Syntax (Toggle Plain Text)
#include <cctype> #include <iostream> #include <string> struct { std::string abbr; std::string name; } state[] = { "AL", "Alabama", "FL", "Florida", "GA", "Georgia", }; const int nstates = 3; std::string get_state ( std::string abbr ) { // Make abbr upper case for ( std::string::size_type i = 0; i < abbr.size(); i++ ) abbr[i] = toupper ( (unsigned char)abbr[i] ); for ( std::string::size_type i = 0; i < nstates; i++ ) { if ( abbr == state[i].abbr ) return state[i].name; } return "NOT FOUND"; } int main() { std::cout<< get_state ( "GA" ) <<std::endl; std::cout<< get_state ( "ME" ) <<std::endl; std::cout<< get_state ( "fl" ) <<std::endl; }
I'm here to prove you wrong.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Comparing arrays
- Next Thread: Problem with pointers
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






