ICAO Alphabet. Extend the program using the switch statement, so that it inputs a string and outputs the series of ICAO words that would be used to spell it out. For example:
Enter string: program
Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike
I am really stuck on this one, my code runs accepts input but
Here is my output:
The corresponding International Civil Aviation Organization (ICAO) alphabet words are: program
program
program
program
program
program
program
program
Here is my code:
#include <iostream>
#include <string>
using namespace std;
void printCode(string s);
int main()
{
string s;
int sz=0;
//PROMPT USER TO PROVIDE INPUT
cout<<"Enter a word to get its ICAO code: ";
//getting user input
cin>>s;
//getting size of the user input
sz= s.size();
cout<<"\nThe corresponding International Civil Aviation Organization (ICAO) alphabet words are: ";
int i=0;
while(i<=sz)
{
printCode://(s.substr(i,1));
cout << s << endl;
i++;
}
//function to print code
void printCode(string s)
{
//switch case to print corresponding word
switch (0)
{
case 'A': case 'a': cout << "Alpha ";
break;
case 'B': case 'b': cout << "Bravo ";
break;
case 'C': case 'c': cout << "Charlie ";
break;
case 'D': case 'd': cout << "Delta ";
break;
case 'E': case 'e': cout << "Echo ";
break;
case 'F': case 'f': cout << "Foxtrot ";
break;
case 'G': case 'g': cout << "Golf ";
break;
case 'H': case 'h': cout << "Hotel ";
break;
case 'I': case 'i': cout << "India ";
break;
case 'J': case 'j': cout << "Juliet ";
break;
case 'K': case 'k': cout << "Kilo ";
break;
case 'L': case 'l': cout << "Lima ";
break;
case 'M': case 'm': cout << "Mike ";
break;
case 'N': case 'n': cout << "November ";
break;
case 'O': case 'o': cout << "Oscar ";
break;
case 'P': case 'p': cout << "Papa ";
break;
case 'Q': case 'q': cout << "Quebec ";
break;
case 'R': case 'r': cout << "Romeo ";
break;
case 'S': case 's': cout << "Sierra ";
break;
case 'T': case 't': cout << "Tango ";
break;
case 'U': case 'u': cout << "Uniform ";
break;
case 'V': case 'v': cout << "Victor ";
break;
case 'W': case 'w': cout << "Whiskey ";
break;
case 'X': case 'x': cout << "X-Ray ";
break;
case 'Y': case 'y': cout << "Yankee ";
break;
case 'Z': case 'z': cout << "Zulu ";
break;
}
}
*************************************************************
Where did I go wrong?? Please Help.
//Prompt
cout<<"\tPlease enter a letter, (A thru Z), that you would like to convert"<< endl;
cout<<"\tto an International Civil Aviation Organization alphabet word"<< endl;
cout<<"\tand press enter.\t"<<endl;
cout<<"\n\n\t";
cin>>instring;
cout<<"Phonetic version is:";
len=instring.length();
void displayChar(char letter)
{
switch (letter)
{
case 'A': case 'a': cout << "Alpha";
break;
case 'B': case 'b': cout << "Bravo";
break;
case 'C': case 'c': cout << "Charlie";
break;
case 'D': case 'd': cout << "Delta";
break;
case 'E': case 'e': cout << "Echo";
break;
case 'F': case 'f': cout << "Foxtrot";
break;
case 'G': case 'g': cout << "Golf";
break;
case 'H': case 'h': cout << "Hotel";
break;
case 'I': case 'i': cout << "India";
break;
case 'J': case 'j': cout << "Juliet";
break;
case 'K': case 'k': cout << "Kilo";
break;
case 'L': case 'l': cout << "Lima";
break;
case 'M': case 'm': cout << "Mike";
break;
case 'N': case 'n': cout << "November";
break;
case 'O': case 'o': cout << "Oscar";
break;
case 'P': case 'p': cout << "Papa";
break;
case 'Q': case 'q': cout << "Quebec";
break;
case 'R': case 'r': cout << "Romeo";
break;
case 'S': case 's': cout << "Sierra";
break;
case 'T': case 't': cout << "Tango";
break;
case 'U': case 'u': cout << "Uniform";
break;
case 'V': case 'v': cout << "Victor";
break;
case 'W': case 'w': cout << "Whiskey";
break;
case 'X': case 'x': cout << "X-Ray";
break;
case 'Y': case 'y': cout << "Yankee";
break;
case 'Z': case 'z': cout << "Zulu";
break;
default : cout << "You entered an invalid letter";