inputing a string word and using Switch statment

Hello, I am working on inputting a word and using the switch statement to output the series of ICAO words. I have been racking my brain over this for 2 days now. This has completely dumb founded me. I hope you can help.
Hello, I am working on inputting a word and using the switch statement to output the series of ICAO words. I have been racking my brain over this for 2 days now. This has completely dumb founded me. I hope you can help.
This is what I came up with. It doesn’t compile and I don't know what to do next?
The input and output should example:
Enter string: program
Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike

This is what I came up with. It doesn’t compile and I don't know what to do next?

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

void displayChar (char letter) ;
int main()
{
	string instring, sub ;
	char letter ;
	int len, ipos ;

	instring = cin.get();
	cout << "Phonetic version for" << instring <<  "is: " ;
	len = instring.length() ;

	ipos = 0;
	while (ipos <= len-1)
	{
		sub = instring.substr(ipos, 1);
		letter = sub[0];
		if (isalpha(letter) == 0)
			cout << "Will skip character " << letter <<  endl;
		else
			displayChar(letter) ;
		ipos = ipos + 1;
		}

	 switch (letter)
	{

	case 'A':cout << "Alpha";                              
		break;
	case 'B':cout << "Bravo";
		break;
	case 'C':cout << "Charlie";
		break;
	case 'D':cout << "Delta";
		break;
	case 'E':cout << "Echo";
		break;
	case 'F':cout << "Foxtrot";
		break;
	case'G':cout << "Golf";
		break;
	case 'H':cout << "Hotel";
		break;
	case 'I':cout << "India"; 
		break;
	case'J':cout << "Juliet";
		break;
	case 'K':cout << "Kilo";
		break;
	case 'L':cout << "Lima";
		break;
	case 'M':cout << "Mike";
		break;
	case 'N':cout << "November";
		break;
	case 'O':cout << "Oscar";
		break;
	case 'P':cout << "Papa";
		break;
	case 'Q':	cout << "Quebec";
		break;
	case 'R':cout << "Romeo";
		break;
	case 'S':	cout << "Sierra";
		break;
	case 'T':cout <<	"Tango";
		break;
	case'U':cout << "Uniforms";
		break;
	case 'V':cout << "Victor";
		break;
	case 'W':cout << "Whiskey";
		break;
	case 'X':	cout << "X-ray";
		break;
	case'Y':cout << "Yankee";
		break;
	case 'Z':cout << "Zulu";
		break;
	default : cout << " is not a valid letter";
}

		
  cin.get();
  cin.get();
  return 0;
}


Thank you for your help.
You haven't defined the function void displayChar(char letter) . Read this:

http://cplusplus.com/doc/tutorial/functions/
Last edited on
you should split the string into single characters and then use your switch-thing...
1. When a code doesn't compile, the output window of the IDE(compiler) shows a list of errors encountered in the output window. Please tell us those errors. They could help us guess what's wrong with your code.

2. Please indent your code correctly. This makes it easier to read.

3. cin.get() inputs a 'char' (actually an int, but doesn't matter as they are compatible) from the console window and returns the character extracted.
So, instring=cin.get() is invalid.

4. The body of the function void displayChar (char letter); is missing.

5. Try using a 'for' loop when using a counter (in this case 'ipos'), to simplify code
for(ipos=0;ipos<=len-1;ipos++)
Thank you all for your quick replies. I was able to get the program working and compiling successfully after reading and researching all your inputs. This was a tuff one, especially as we have not even learned about Void functions in class yet, but for some reason, had to implement it into this program. I guess now when we get to the Void Chapter, I will be ahead of the game, or so I hope. Thanks again.
np
4. The body of the function void displayChar (char letter); is missing.


What would the body of the function be in code?
Topic archived. No new replies allowed.