ICAO Program with function.. help?

The instructions for my assignment are pretty simple design a program that takes user input in the form of a string and transform it into corresponding phrases from the ICAO phonetic alphabet. We were also tasked with editing a previous assignment that performs the same result but we must use a void function to complete the assignment this time around.

I can get my new program to run but it won't give me any output. Can anyone tell me where I'm going wrong.


#include <iostream>
#include <string>

using namespace std;
void ICAO(string);


int main()
{
string wrd_inpt, wrd_op;
//Prompt for end user input
cout << "Please a sentence/word for processing: " << endl;
cin >> wrd_inpt;

ICAO(wrd_inpt);

//Displays output for end user
cout << "Phonetic version is: " << wrd_op << endl;
cin.get();
cin.get();
}
//Function definition
void ICAO(string wrd_inpt)
{
int len, ipos{};
string wrd_op;
char letter;

len = wrd_inpt.length();

for (ipos = 0; ipos < wrd_inpt.length(); ipos + 1)
{
letter = wrd_inpt.at(ipos);

switch (letter)
{
case 'a': case 'A':
wrd_op += "Alpha ";
break;
case 'b': case'B':
wrd_op += "Beta ";
break;
case 'c': case'C':
wrd_op += "Charlie ";
break;
case'd':case'D':
wrd_op += "Delta ";
break;
case 'e':case 'E':
wrd_op += "Echo ";
break;
case'f':case 'F':
wrd_op += "Foxtrot ";
break;
case'g':case 'G':
wrd_op += "Golf ";
break;
case'h':case 'H':
wrd_op += "Hotel ";
break;
case 'i':case 'I':
wrd_op += "India ";
break;
case'j':case 'J':
wrd_op += "Juliet ";
break;
case'k':case 'K':
wrd_op += "Kilo ";
break;
case 'l':case 'L':
wrd_op += "Lima ";
break;
case'm':case 'M':
wrd_op += "Mike ";
break;
case 'n':case 'N':
wrd_op += "November ";
break;
case'o':case 'O':
wrd_op += "Oscar ";
break;
case 'p':case 'P':
wrd_op += "Papa ";
break;
case 'q':case 'Q':
wrd_op += "Quebec ";
break;
case 'r':case 'R':
wrd_op += "Romeo ";
break;
case 's':case 'S':
wrd_op += "Sierra ";
break;
case 't':case 'T':
wrd_op += "Tango ";
break;
case 'u':case 'U':
wrd_op += "Uniform ";
break;
case 'v':case 'V':
wrd_op += "Victor ";
break;
case 'w':case 'W':
wrd_op += "Whiskey ";
break;
case 'x':case 'X':
wrd_op += "X-Ray ";
break;
case 'y':case 'Y':
wrd_op += "Yankee ";
break;
case 'z':case 'Z':
wrd_op += "Zulu ";
break;

ipos = ipos + 1;
}

}
}
Last edited on
Lets look at your program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>

using namespace std;

void ICAO( string );

int main()
{
  string wrd_inpt, wrd_op; // create wrd_op
  //Prompt for end user input
  cout << "Please a sentence/word for processing: " << endl;
  cin >> wrd_inpt;

  ICAO( wrd_inpt );

  //Displays output for end user
  cout << "Phonetic version is: " << wrd_op << endl; // show wrd_op
  cin.get();
  cin.get();
}

An empty string "wrd_op" is created on line 10 and shown on line 18.
Nothing changes wrd_op between those lines.

You are not allowed to return a value from ICAO(), but could you pass a parameter by reference?


PS. Code tags make posted code more readable.
I was able to fix it by moving the output prompt around a bit. Thank you for your help!
Topic archived. No new replies allowed.