Counting string length and converting char

I'm trying to convert a string into its ICAO phonetic phrase using a function, but I'm having trouble breaking the string into individual characters to use in the function and then print. So far every string will just use Alpha and print that as many times as the length of the string, I have a loop to switch characters but I don't know if it's actually recognizing it and there is a mismatch with my < userWord.length() that I'm not sure how to go about fixing, or is my function set up wrong?

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

string convert(char letter)
{
	string icaoword;

	if (letter=='a'||'A')
	{
		icaoword = "Alpha";
	}
	else if (letter=='b'||'B')
	{
		icaoword = "Bravo";
	}
	
	else if (letter=='c'||'C')
	{
		icaoword = "Charlie";
	}

	else if (letter=='d'||'D')
	{
		icaoword = "Delta";
	}

	else if (letter=='e'||'E')
	{
		icaoword = "Echo";
	}

	else if (letter=='f'||'F')
	{
		icaoword = "Foxtrot";
	}

	else if (letter=='g'||'G')
	{
		icaoword = "Golf";
	}

	else if (letter=='h'||'H')
	{
		icaoword = "Hotel";
	}

	else if (letter=='i'||'I')
	{
		icaoword = "India";
	}

	else if (letter=='j'||'J')
	{
		icaoword = "Juliet";
	}

	else if (letter=='k'||'K')
	{
		icaoword = "Kilo";
	}

	else if (letter=='l'||'L')
	{
		icaoword = "Lima";
	}

	else if (letter=='m'||'M')
	{
		icaoword = "Mike";
	}

	else if (letter=='n'||'N')
	{
		icaoword = "November";
	}

	else if (letter=='o'||'O')
	{
		icaoword = "Oscar";
	}

	else if (letter=='p'||'P')
	{
		icaoword = "Papa";
	}

	else if (letter=='q'||'Q')
	{
		icaoword = "Quebec";
	}

	else if (letter=='r'||'R')
	{
		icaoword = "Romeo";
	}

	else if (letter=='s'||'S')
	{
		icaoword = "Sierra";
	}

	else if (letter=='t'||'T')
	{
		icaoword = "Tango";
	}

	else if (letter=='u'||'U')
	{
		icaoword = "Uniform";
	}

	else if (letter=='v'||'V')
	{
		icaoword = "Victor";
	}

	else if (letter=='w'||'W')
	{
		icaoword = "Whiskey";
	}

	else if (letter=='x'||'X')
	{
		icaoword = "X-ray";
	}

	else if (letter=='y'||'Y')
	{
		icaoword = "Yankee";
	}

	else if (letter=='z'||'Z')
	{
		icaoword = "Zulu";
	}

	return icaoword;

}

int main()
{
	string userWord;
	cout<<"Enter a string with a period at the end"<<endl;
	cin >> userWord;
	int i = 0;
	while (i<(userWord.length()))
	{
	char letter = userWord[i];
	string word = convert(letter);
	cout<<word<<" ";
	i++;
	}
	cout<<endl;
return 0;
}
if statements should look like this
1
2
3
4
	if (letter == 'a' || letter == 'A')
	{
		icaoword = "Alpha";
	}
I suddenly feel super dumb because I know that's how the statement should look... But at least it works! Thank you
Topic archived. No new replies allowed.