I need help so bad. I don't understand enum and I have tried to take the code below and change it from the Switch to using an enum & an array to supposedly make it easier. I don't know how to take the user input that is string and put it to the myEnum(a, b, c, d,);
This is the code I have but no way to convert:
enum Alphabet {A = 0, B = 1, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z};
Alphabet whichone;
I also have an array
string phoneticName[] = {"Alpha ", "Beta ", "Charlie ", "Delta ",
"Echo ", "Foxtrot ", "Golf ", "Hotel ", "India ", "Juliet ",
"Kilo ", "Lima ", "Mike ", "November ", "Oscar ", "Papa ",
"Quebec ", "Romeo ", "Sierra ", "Tango ", "Uniform ", "Victor ",
"Whiskey ", "X-Ray ", "Yankee","Zulu" };
This is my original code:
It take a string input and output each character Aviation Term:
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;
void GetAlpha(char);
int main()
{
string inputword;
int charcount;
string displayeachletter;
char oneletter;
int convertocharnum;
cout << "Enter a string and press enter" << endl;
cin >> inputword;
cout << "The phonetic version of this word is: " << endl;
// Loop through the inputword and decrease counter
charcount = 0;
for (charcount = inputword.length() - 1; charcount >= 0; charcount--)
{
// Determine the position number of each word
convertocharnum = inputword.length() - 1 - charcount;
cout << convertocharnum << endl;
// Create single character for each word
displayeachletter = inputword.substr(convertocharnum, 1);
// Convert the string char to a real char for the switch function
oneletter = displayeachletter[0];
// Call Switch Function
GetAlpha(oneletter);
}
return 0;
}
void GetAlpha ( /* in */ char oneletter)
{
//string letter
switch (oneletter)
{
case 'a' : cout << "A = Alpha" << endl; break;
case 'A' : cout << "A = Alpha" << endl; break;
case 'b' : cout << "B = Beta" << endl; break;
case 'B' : cout << "B = Beta" << endl; break;
case 'c' : cout << "C = Charlie" << endl; break;
case 'C' : cout << "C = Charlie" << endl; break;
case 'd' : cout << "D = Delta" << endl; break;
case 'D' : cout << "D = Delta" << endl; break;
case 'e' : cout << "E = Echo" << endl; break;
case 'E' : cout << "E = Echo" << endl; break;
case 'f' : cout << "F = Foxtrot" << endl; break;
case 'F' : cout << "F = Foxtrot" << endl; break;
case 'g' : cout << "G = Golf" << endl; break;
case 'G' : cout << "G = Golf" << endl; break;
case 'h' : cout << "H = Hotel" << endl; break;
case 'H' : cout << "H = Hotel" << endl; break;
case 'i' : cout << "I = India" << endl; break;
case 'I' : cout << "I = India" << endl; break;
case 'j' : cout << "J = Juliet" << endl; break;
case 'J' : cout << "J = Juliet" << endl; break;
case 'k' : cout << "K = Kilo" << endl; break;
case 'K' : cout << "K = Kilo" << endl; break;
case 'l' : cout << "L = Lima" << endl; break;
case 'L' : cout << "L = Lima" << endl; break;
case 'm' : cout << "M = Mike" << endl; break;
case 'M' : cout << "M = Mike" << endl; break;
case 'n' : cout << "N = November" << endl; break;
case 'N' : cout << "N = November" << endl; break;
case 'o' : cout << "O = Oscar" << endl; break;
case 'O' : cout << "O = Oscar" << endl; break;
case 'p' : cout << "P = Papa" << endl; break;
case 'P' : cout << "P = Papa" << endl; break;
case 'q' : cout << "Q = Quebec" << endl; break;
case 'Q' : cout << "Q = Quebec" << endl; break;
case 'r' : cout << "R = Romeo" << endl; break;
case 'R' : cout << "R = Romeo" << endl; break;
case 's' : cout << "S = Sierra" << endl; break;
case 'S' : cout << "S = Sierra" << endl; break;
case 't' : cout << "T = Tango" << endl; break;
case 'T' : cout << "T = Tango" << endl; break;
case 'u' : cout << "U = Uniform" << endl; break;
case 'U' : cout << "U = Uniform" << endl; break;
case 'v' : cout << "V = Victor" << endl; break;
case 'V' : cout << "V = Victor" << endl; break;
case 'w' : cout << "W = Whiskey" << endl; break;
case 'W' : cout << "W = Whiskey" << endl; break;
case 'x' : cout << "X = X-Ray" << endl; break;
case 'X' : cout << "X = X-Ray" << endl; break;
case 'y' : cout << "Y = Yankee" << endl; break;
case 'Y' : cout << "Y = Yankee" << endl; break;
case 'z' : cout << "Z = Zulu" << endl; break;
case 'Z' : cout << "Z = Zulu" << endl; break;
default : cout << "try again" << endl;
}
}
ANY help or explanation would be greatly appreciated. This is my assignment for class and I can make it work but not with enum and array.
Thanks,
Hope