ICAO Alphabet program

Hello, when I try to run my code it gives me an error on line 28. I am having a difficult time figuring out what I am doing wrong. It might be super obvious but i've been staring at it for a while and can't figure it out. Any hints?

Here's the assignment:
Write a program that asks the user to enter a single word and outputs the series of ICAO words that would be used to spell it out. The corresponding International Civil Aviation Organization alphabet or ICAO words are the words that pilots use when they need to spell something out over a noisy radio channel.

See sample screen output for an example:

Enter a word: program
Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike

The specific requirement is that you write the program so that it determines the word corresponding to a specified letter using a Switch statement instead of an If structure.
As a point of reference, the ICAO alphabet is included below:


A Alpha N November
B Bravo O Oscar
C Charlie P Papa
D Delta Q Quebec
E Echo R Romeo
F Foxtrot S Sierra
G Golf T Tango
H Hotel U Uniform
I India V Victor
J Juliet W Whiskey
K Kilo X X-Ray
L Lima Y Yankee
M Mike Z Zulu


[code
#include <iostream>
#include <string>
using namespace std;

int main()
{
// Declare the variables you will use
string Word_Input;
string Word_Output = " ";
char Letters;

// Ask the user to enter a word.

cout<< " Enter a word: ";
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);

// Program will retrieve the appropriate ICAO word to match the character

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

return0;


}

[/code]
You have - case 'B ': case 'a': rather then case 'B ': case 'b':

Look at your case H too.
Last edited on
AHHAHAHA. Beautiful,thank you much! But it's still giving me an error on that same line
Last edited on
You're welcome.

Also you might want to add V.
I think I have multiple errors because it keeps giving me the same error on line 28 even after fixing it
Ooooh I dont have switch{}
Fixed
output:
Enter a word: program
Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike

Process returned 0 (0x0) execution time : 3.837 s
Press any key to continue.



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
#include <iostream>
#include <string>
using namespace std;

int main()
{
    // Declare the variables you will use
    string Word_Input;
    string Word_Output = " ";
    char Letters;

    // Ask the user to enter a word.

    cout<< " Enter a word: ";
    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);

        // Program will retrieve the appropriate ICAO word to match the character

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

    //Display the ICAO words
    cout<< " Phonetic version is: " << Word_Output<<endl;
    return 0;
}






Fixed :D, again thanks!!

Topic archived. No new replies allowed.