C++ program that converts word or name to ICAO. Wont print my ICAO results.

This is my code that I am struggling to get the results (ICAO words) printed. My code has to use functions, have a user menu, and cant use arrays. Whenever I do not have a user menu or functions then the code runs perfectly. As soon as I add everything else, it does not seem to print the results. Any advice?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

void userInput();
void wordToICAO();
void userMenu();
int main(int argc, char** argv)
  {
   userMenu();
   userInput();
   wordToICAO();
   
   cout << endl << endl;

    return 0;
 } // End of main function() 

void userMenu()

{
    int choice;
    do
    {
    cout << "  ___________________________________"  << endl;
    cout << " |This program takes user input of a |" << endl;
    cout << " |word or name and displays the word |" << endl;
    cout << " |or name in the International Civil |" << endl;
    cout << " |Aviation Organization Alphabet     |" << endl;
    cout << " |-----------------------------------|" << endl;
    cout << " |                  MENU             |" << endl;
    cout << " |      0: Quit Program              |" << endl;
    cout << " |      1: Print to ICAO             |" << endl;
    cout << " |-----------------------------------|" << endl;
    cout << " |      Enter your choice:           |" << endl;
    cin >> choice;
    
    switch(choice)
    {
    case 0: cout << "Exiting Program" << endl;
         break;
    case 1: userInput();
            wordToICAO();
         break;
    default: cout << "Invalid choice, try again!" << endl;
    }
    
    }
    while( choice != 0 );

} // End of userMenu()


void userInput()
{
    string Word_Input;            // Disclose the varibles you will use
    char Letters;
  { 

    cout<< " Enter a word or name: ";    // Ask the user to enter a word or name
    cin>> Word_Input;

       for(int i = 0; i < Word_Input.length(); i++)
    {
        // characters must be processed one at a time
        Letters = Word_Input.at (i);
    }
  } 
} // End of userInput()


void wordToICAO()
 {   
    string Word_Input;            
    string Wrd_Otpt = " ";   
    char Letters;
 
{
        // Program will retrieve the appropriate ICAO word to match the character

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

    //Display the ICAO words
    cout<< " Phonetic version is:" << Wrd_Otpt<<endl;
    cout << endl << endl;

     
 } // End of wordToICAO() 
Last edited on
1
2
3
4
5
6
7
8
9
void wordToICAO()
{
string Word_Input;
string Wrd_Otpt = " ";
char Letters;
{
// Program will retrieve the appropriate ICAO word to match the character

switch(Letters)

Letters is an uninitialized variable.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Functions can take arguments and return a value. See http://www.cplusplus.com/doc/tutorial/functions/

Your function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void userInput()
{
  string Word_Input;
  char Letters; // local variable; will store one character
  {
    cout<< " Enter a word or name: ";
    cin>> Word_Input;

    for(int i = 0; i < Word_Input.length(); i++)
    {
      Letters = Word_Input.at (i);  // each assignment overwrites the Letters
    }
    // Letters now has last character of Word_Input
  }
} // Letters is destroyed here 

We get no data by calling userInput() because it does not pass anything to us.

Note how you call function string::at(): Letters = Word_Input.at (i);
You pass data, argument 'i' to the function.
You receive data; store the return value of at() into variable 'Letters'.
Topic archived. No new replies allowed.