Yes, but if you use the
else statement, it will stop looking for other possibilities once the correct one is found.
Since this has to do with
functional decomposition, I suggest you use a function somewhere in there. Try one with a prototype something like:
string ICAO_code( char letter );
You might want to consider the possibility that the input letter will
not be majuscule; be sure to
#include <cctype>
and use the
toupper() function.
Another thought is that you can avoid all those
if..
else if.. statements with a simple lookup table.
1 2 3 4 5 6 7
|
const char* ICAO_CODES[ 26 ] =
{
"Alpha",
"Bravo",
"Charlie",
...
};
|
You can convert the letter itself into an index into the array via
index = letter - 'A';
Your initial problem is that you were trying to compare a
char ('A') with a
char* ("A")-- which are two different things. Either compare
chars to
chars, or (as
MYST suggested) use the STL
string class to compare strings (a
string to
char* comparison is defined by the STL.)
Hope this helps.