This should be easy but I have tried and failed

How do I use to upper so that if any alphabet is entering in lowercase it will be moved to uppercase. I use the entire alphabet in the code.

#include <iostream> // For cout, cin
#include <string>
#include <istream>
#include <ostream>
#include <iomanip>
#include <cctype> // For toupper
using namespace std;



int main()
{

char inputLetter; // Declar char variables.
inputLetter = toupper(inputLetter);
char inputLetter1 = 'A';
char inputLetter2 = 'B';
char inputLetter3 = 'C';
char inputLetter4 = 'D';
char inputLetter5 = 'E';
char inputLetter6 = 'F';
char inputLetter7 = 'G';
char inputLetter8 = 'H';
char inputLetter9 = 'I';
char inputLetter10 = 'J';
char inputLetter11 = 'K';
char inputLetter12 = 'L';
char inputLetter13 = 'M';
char inputLetter14 = 'N';
char inputLetter15 = 'O';
char inputLetter16 = 'P';
char inputLetter17 = 'Q';
char inputLetter18 = 'R';
char inputLetter19 = 'S';
char inputLetter20 = 'T';
char inputLetter21 = 'U';
char inputLetter22 = 'V';
char inputLetter23 = 'W';
char inputLetter24 = 'X';
char inputLetter25 = 'Y';
char inputLetter26 = 'Z';

string outputWord; // Declare string variables.
string outputWord1 = "Alpha";
string outputWord2 = "Bravo";
string outputWord3 = "Charlie";
string outputWord4 = "Delta";
string outputWord5 = "Echo";
string outputWord6 = "Foxtrot";
string outputWord7 = "Golf";
string outputWord8 = "Hotel";
string outputWord9 = "India";
string outputWord10 = "Juliet";
string outputWord11 = "Kilo";
string outputWord12 = "Lima";
string outputWord13 = "Mike";
string outputWord14 = "November";
string outputWord15 = "Oscar";
string outputWord16 = "Papa";
string outputWord17 = "Quebe";
string outputWord18 = "Romeo";
string outputWord19 = "Sierra";
string outputWord20 = "Tango";
string outputWord21 = "Uniform";
string outputWord22 = "Victor";
string outputWord23 = "Whiskey";
string outputWord24 = "X-ray";
string outputWord25 = "Yankee";
string outputWord26 = "Zulu";




cout << "Enter a letter to find the corresponding International Civil Aviation Organization alphabet word" << endl;
cin >> inputLetter;


if (inputLetter == inputLetter1) // I/O direction for the program.
{
inputLetter = inputLetter1;
cout << outputWord1 << endl;
}

else if (inputLetter == inputLetter2)
{
inputLetter = inputLetter2;
cout << outputWord2 << endl;
}

else if (inputLetter == inputLetter3)
{
inputLetter = inputLetter3;
cout << outputWord3 << endl;
}

else if (inputLetter == inputLetter4)
{
inputLetter = inputLetter4;
cout << outputWord4 << endl;
}

else if (inputLetter == inputLetter5)
{
inputLetter = inputLetter5;
cout << outputWord5 << endl;
}

else if (inputLetter == inputLetter6)
{
inputLetter = inputLetter6;
cout << outputWord6 << endl;
}

else if (inputLetter == inputLetter7)
{
inputLetter = inputLetter7;
cout << outputWord7 << endl;
}

else if (inputLetter == inputLetter8)
{
inputLetter = inputLetter8;
cout << outputWord8 << endl;
}

else if (inputLetter == inputLetter9)
{
inputLetter = inputLetter9;
cout << outputWord9 << endl;
}

else if (inputLetter == inputLetter10)
{
inputLetter = inputLetter10;
cout << outputWord10 << endl;
}

else if (inputLetter == inputLetter11)
{
inputLetter = inputLetter11;
cout << outputWord11 << endl;
}

else if (inputLetter == inputLetter12)
{
inputLetter = inputLetter12;
cout << outputWord12 << endl;
}

else if (inputLetter == inputLetter13)
{
inputLetter = inputLetter13;
cout << outputWord13 << endl;
}

else if (inputLetter == inputLetter14)
{
inputLetter = inputLetter14;
cout << outputWord14 << endl;
}

else if (inputLetter == inputLetter15)
{
inputLetter = inputLetter15;
cout << outputWord15 << endl;
}

else if (inputLetter == inputLetter16)
{
inputLetter = inputLetter16;
cout << outputWord16 << endl;
}

else if (inputLetter == inputLetter17)
{
inputLetter = inputLetter17;
cout << outputWord17 << endl;
}

else if (inputLetter == inputLetter18)
{
inputLetter = inputLetter18;
cout << outputWord18 << endl;
}

else if (inputLetter == inputLetter19)
{
inputLetter = inputLetter19;
cout << outputWord19 << endl;
}

else if (inputLetter == inputLetter20)
{
inputLetter = inputLetter20;
cout << outputWord20 << endl;
}

else if (inputLetter == inputLetter21)
{
inputLetter = inputLetter21;
cout << outputWord21 << endl;
}

else if (inputLetter == inputLetter22)
{
inputLetter = inputLetter22;
cout << outputWord22 << endl;
}

else if (inputLetter == inputLetter23)
{
inputLetter = inputLetter23;
cout << outputWord23 << endl;
}

else if (inputLetter == inputLetter24)
{
inputLetter = inputLetter24;
cout << outputWord24 << endl;
}

else if (inputLetter == inputLetter25)
{
inputLetter = inputLetter25;
cout << outputWord25 << endl;
}

else if (inputLetter == inputLetter26)
{
inputLetter = inputLetter26;
cout << outputWord26 << endl;
}

else
{
cout << "Please restart program and try again" << endl;
cin >> inputLetter;
}

cin.get () ;
cin.get () ;

return 0;

}
Please use code tags:
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include <iostream> // For cout, cin
#include <string>
#include <istream>
#include <ostream>
#include <iomanip>
#include <cctype> // For toupper
using namespace std;



int main()
{

char inputLetter; // Declar char variables.
inputLetter = toupper(inputLetter);
char inputLetter1 = 'A';
char inputLetter2 = 'B';
char inputLetter3 = 'C';
char inputLetter4 = 'D';
char inputLetter5 = 'E';
char inputLetter6 = 'F';
char inputLetter7 = 'G';
char inputLetter8 = 'H';
char inputLetter9 = 'I';
char inputLetter10 = 'J';
char inputLetter11 = 'K';
char inputLetter12 = 'L';
char inputLetter13 = 'M';
char inputLetter14 = 'N';
char inputLetter15 = 'O';
char inputLetter16 = 'P';
char inputLetter17 = 'Q';
char inputLetter18 = 'R';
char inputLetter19 = 'S';
char inputLetter20 = 'T';
char inputLetter21 = 'U';
char inputLetter22 = 'V';
char inputLetter23 = 'W';
char inputLetter24 = 'X';
char inputLetter25 = 'Y';
char inputLetter26 = 'Z';

string outputWord; // Declare string variables.
string outputWord1 = "Alpha";
string outputWord2 = "Bravo";
string outputWord3 = "Charlie";
string outputWord4 = "Delta";
string outputWord5 = "Echo";
string outputWord6 = "Foxtrot";
string outputWord7 = "Golf";
string outputWord8 = "Hotel";
string outputWord9 = "India";
string outputWord10 = "Juliet";
string outputWord11 = "Kilo";
string outputWord12 = "Lima";
string outputWord13 = "Mike";
string outputWord14 = "November";
string outputWord15 = "Oscar";
string outputWord16 = "Papa";
string outputWord17 = "Quebe";
string outputWord18 = "Romeo";
string outputWord19 = "Sierra";
string outputWord20 = "Tango";
string outputWord21 = "Uniform";
string outputWord22 = "Victor";
string outputWord23 = "Whiskey";
string outputWord24 = "X-ray";
string outputWord25 = "Yankee";
string outputWord26 = "Zulu";




cout << "Enter a letter to find the corresponding International Civil Aviation Organization alphabet word" << endl;
cin >> inputLetter;


if (inputLetter == inputLetter1) // I/O direction for the program.
{
inputLetter = inputLetter1;
cout << outputWord1 << endl;
}

else if (inputLetter == inputLetter2)
{
inputLetter = inputLetter2;
cout << outputWord2 << endl;
}

else if (inputLetter == inputLetter3)
{
inputLetter = inputLetter3;
cout << outputWord3 << endl;
}

else if (inputLetter == inputLetter4)
{
inputLetter = inputLetter4;
cout << outputWord4 << endl;
}

else if (inputLetter == inputLetter5)
{
inputLetter = inputLetter5;
cout << outputWord5 << endl;
}

else if (inputLetter == inputLetter6)
{
inputLetter = inputLetter6;
cout << outputWord6 << endl;
}

else if (inputLetter == inputLetter7)
{
inputLetter = inputLetter7;
cout << outputWord7 << endl;
}

else if (inputLetter == inputLetter8)
{
inputLetter = inputLetter8;
cout << outputWord8 << endl;
}

else if (inputLetter == inputLetter9)
{
inputLetter = inputLetter9;
cout << outputWord9 << endl;
}

else if (inputLetter == inputLetter10)
{
inputLetter = inputLetter10;
cout << outputWord10 << endl;
}

else if (inputLetter == inputLetter11)
{
inputLetter = inputLetter11;
cout << outputWord11 << endl;
}

else if (inputLetter == inputLetter12)
{
inputLetter = inputLetter12;
cout << outputWord12 << endl;
}

else if (inputLetter == inputLetter13)
{
inputLetter = inputLetter13;
cout << outputWord13 << endl;
}

else if (inputLetter == inputLetter14)
{
inputLetter = inputLetter14;
cout << outputWord14 << endl;
}

else if (inputLetter == inputLetter15)
{
inputLetter = inputLetter15;
cout << outputWord15 << endl;
}

else if (inputLetter == inputLetter16)
{
inputLetter = inputLetter16;
cout << outputWord16 << endl;
}

else if (inputLetter == inputLetter17)
{
inputLetter = inputLetter17;
cout << outputWord17 << endl;
}

else if (inputLetter == inputLetter18)
{
inputLetter = inputLetter18;
cout << outputWord18 << endl;
}

else if (inputLetter == inputLetter19)
{
inputLetter = inputLetter19;
cout << outputWord19 << endl;
}

else if (inputLetter == inputLetter20)
{
inputLetter = inputLetter20;
cout << outputWord20 << endl;
}

else if (inputLetter == inputLetter21)
{
inputLetter = inputLetter21;
cout << outputWord21 << endl;
}

else if (inputLetter == inputLetter22)
{
inputLetter = inputLetter22;
cout << outputWord22 << endl;
}

else if (inputLetter == inputLetter23)
{
inputLetter = inputLetter23;
cout << outputWord23 << endl;
}

else if (inputLetter == inputLetter24)
{
inputLetter = inputLetter24;
cout << outputWord24 << endl;
}

else if (inputLetter == inputLetter25)
{
inputLetter = inputLetter25;
cout << outputWord25 << endl;
}

else if (inputLetter == inputLetter26)
{
inputLetter = inputLetter26;
cout << outputWord26 << endl;
}

else
{
cout << "Please restart program and try again" << endl;
cin >> inputLetter;
}

cin.get () ;
cin.get () ;

return 0;

}
Move "inputLetter = toupper(inputLetter);" on line 15
to below "cin >> inputLetter;" on line 75.

This will now convert the input to uppercase after it has been entered.

Because nothing was entered before "toupper", nothing was being converted.

Hope this helps!
Thank you very much this worked!
I will now accept the capital and lower case with both output as upper case.
You should be terribly afraid of repetitive code. If you later realized you had to print the next ICAO word instead of the corresponding one, you would have to edit your code in 26 places, and invariably miss one or two of those spots.

Here is one way to get rid of some of the redundancy:

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
# include <iostream> // For cout, cin
# include <string>
# include <map>
# include <cctype> // For toupper

static std::map <char, std::string> const ICAO_alphabet {
  {'A', "Alpha"   }, {'B', "Bravo"   }, {'C', "Charlie" }, {'D', "Delta"   },
  {'E', "Echo"    }, {'F', "Foxtrot" }, {'G', "Golf"    }, {'H', "Hotel"   },
  {'I', "India"   }, {'J', "Juliet"  }, {'K', "Kilo"    }, {'L', "Lima"    },
  {'M', "Mike"    }, {'N', "November"}, {'O', "Oscar"   }, {'P', "Papa"    },
  {'Q', "Quebe"   }, {'R', "Romeo"   }, {'S', "Sierra"  }, {'T', "Tango"   },
  {'U', "Uniform" }, {'V', "Victor"  }, {'W', "Whiskey" }, {'X', "X-ray"   },
  {'Y', "Yankee"  }, {'Z', "Zulu"    }
};

int main() {
  std::cout << "Enter a letter to find the corresponding International Civil"
       << " Aviation Organization alphabet word\n";
  char letter = 0;
  if (std::cin >> letter) {
    try { 
      std::cout << ICAO_alphabet.at(std::toupper(letter)) << "\n"; 
      return 0;
    }
    catch (std::out_of_range) { /* Do nothing */ }
  }

  std::cout << "Please restart the program and try again.\n";
}

Last edited on
Thanks this is definitely a better program! However, with my lack of experience in C++ much of this hasn't been covered. I tried implementing this but without knowledge of how to correct the errors that result I'm stuck. At this point I have to use this same program to create phonetic breakdowns with a switch statement. I'm having fun nevertheless :).
Topic archived. No new replies allowed.