///
// Program; Project2.cpp
// Date;
// Purpose:
// Description:
// Input:
// Output:
// Use: This program is compiled and executed using
// Microsoft Visual Studio C++.net 2003 Version 7.1
#include "stdafx.h"
#include <iostream> // access input/output stream.
#include <string>
#include <cctype>
using namespace std;
int StateNumber(char, char);
void StateText(string);
int main()
{
int a; // to hold the output screen
char firstLetter; // can you set char's = 0?
char secondLetter;
string stateName;
cout << " STATE POSTAL CODE CONVERTER\n\n";
cout << "Enter the two character Postal Code to see\n"
<< "it's corresponding State. (for example AK)\n\n";
cin >> firstLetter >> secondLetter;
while ( (firstLetter != 'E') && (secondLetter != 'X') )
{
switch (StateNumber(firstLetter, secondLetter))
{
case 6575:
StateText("Alaska");
break;
case 6576:
StateText("Alabama");
break;
case 6582:
StateText("Arkansas");
break;
case 6590:
StateText("Arizona");
break;
case 6765:
StateText("California");
break;
case 6779:
StateText("Colorado");
break;
case 6784:
StateText("Connecticut");
break;
case 6869:
StateText("Delaware");
break;
case 7076:
StateText("Florida");
break;
case 7165:
StateText("Georgia");
break;
case 7273:
StateText("Hawaii");
break;
case 7365:
StateText("Iowa");
break;
case 7368:
StateText("Idaho");
break;
case 7376:
StateText("Illinois");
break;
case 7378:
StateText("Indiana");
break;
case 7583:
StateText("Kansas");
break;
case 7589:
StateText("Kentucky");
break;
case 7665:
StateText("Louisiana");
break;
case 7765:
StateText("Massachusetts");
break;
case 7768:
StateText("Maryland");
break;
case 7769:
StateText("Maine");
break;
case 7773:
StateText("Michigan");
break;
case 7778:
StateText("Minnesota");
break;
case 7779:
StateText("Missouri");
break;
case 7783:
StateText("Mississippi");
break;
case 7784:
StateText("Montana");
break;
case 7867:
StateText("North Carolina");
break;
case 7868:
StateText("North Dakota");
break;
case 7869:
StateText("Nebraska");
break;
case 7872:
StateText("New Hampshire");
break;
case 7874:
StateText("New Jersey");
break;
case 7877:
StateText("New Mexico");
break;
case 7886:
StateText("Nevada");
break;
case 7889:
StateText("New York");
break;
case 7972:
StateText("Ohio");
break;
case 7975:
StateText("Oklahoma");
break;
case 7982:
StateText("Oregon");
break;
case 8065:
StateText("Pennsylvania");
break;
case 8273:
StateText("Rhode Island");
break;
case 8367:
StateText("South Carolina");
break;
case 8368:
StateText("South Dakota");
break;
case 8478:
StateText("Tennessee");
break;
case 8488:
StateText("Texas");
break;
case 8584:
StateText("Utah");
break;
case 8665:
StateText("Virginia");
break;
case 8684:
StateText("Vermont");
break;
case 8765:
StateText("Washington");
break;
case 8773:
StateText("Wisconsin");
break;
case 8786:
StateText("West Virginia");
break;
case 8789:
StateText("Wyoming");
break;
default:
cout << '\n' << firstLetter << secondLetter << " is not a valid Postal Code!\n\n";
}
cout << "Enter another State Postal Code or \"EX\" to exit\n\n";
cin >> firstLetter >> secondLetter;
}
cout << "\nGOOD BYE!";
for(a = 1; a < 3000000000; a++); // acts as a pause before the output screen goes away
return 0;
}
int StateNumber(char chr1, char chr2)
{
int stateValue = 0;
int A = 0;
int B = 0;
A = (int)chr1;
B = (int)chr2;
stateValue = (A * 100 + B);
return stateValue;
}
void StateText(string stateName)
{
cout << "The State you selected is " << stateName << "!" << endl;
}
wheelz 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
wheelz 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
wheelz 0 Newbie Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
wheelz 0 Newbie Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
iamthwee
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
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.