I cant not get ths prgram to stop asking for input. I don't know when the problem is . I think it's in the do-while statement, but I can not figure it out. I have not included all the state initials (too long). What you reckon???
Code:
#include <iostream>
#include <string>
#include <ctype>
void PrintDescription();
void InputInitials(char&, char&);
void GetStateName(char&, char&);
void HoldScreen();
int main()
{
char initial_1;
char initial_2;
PrintDescription();
do
{
GetStateName(initial_1, initial_2);
}while(true);
cin.get();
HoldScreen();
return 0;
}
//------------------------------------------------------------------------------
/* This function outputs a description of the program to the user */
void PrintDescription(/* out */)
{
cout << "\nThis program inputs a two-letter abbreviation for one of "
"the 50 states and \n";
cout << "prints out the full name of the state. If the abbreviation"
" is not valid \n";
cout << "the program will output an error message and ask for the "
"abbreviation again.\n";
return;
}
//------------------------------------------------------------------------------
// This function prompts user for the initials of a State name
void InputInitials(/* out */char& initial_1,
/* out */char& initial_2)
{
cout << "\nPlease enter the States two initial.\n" << '\n';
cin >> initial_1 >> initial_2;
cin.ignore(10, '\n');
initial_1 = toupper(initial_1);
initial_2 = toupper(initial_2);
return;
}
//------------------------------------------------------------------------------
// This function prints out the states full name
void GetStateName(/* out */char& initial_1,
/* out */char& initial_2)
{
InputInitials(initial_1, initial_2);
switch(initial_1)
{
case 'A':
{
switch (initial_2)
{
case 'K' :
cout << "Alaska";
break;
case 'L' :
cout << "Alabama";
break;
case 'R' :
cout << "Arkansas";
break;
case 'Z' :
cout << "Arizona";
break;
default:
cout << "\nInvalid abbreviation entered.\n";
}
break;
}
case 'C':
{
switch(initial_2)
{
case 'A' :
cout << "California";
break;
case 'O' :
cout << "Colorado";
break;
case 'T' :
cout << "Connecticut";
break;
default :
cout << "\nInvalid abbreviation entered.\n";
}
break;
}
case 'D':
{
switch (initial_2)
{
case 'E' :
cout << "Delaware";
break;
default :
cout << "\nInvalid abbreviation entered.\n";
}
break;
}
default :
cout << "\nInvalid abbreviation entered.\n";
return;
}
}
//------------------------------------------------------------------------------
void HoldScreen(/* out */)
{
cout << "\nDesigned by Loranne Wish. " << '\n';
cout << "Press enter to continue.";
cin.get();
return;
}