Join 150,018 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,464 people online right now. Registration is fast and FREE... Join Now!
cout << "Input a word to return in ICAO form: " << endl;
string icaoword; cin >> icaoword;
for(int i=0; i < icaoword.length(); ++i) { std::string strOutput; char cLetter; cLetter = icaoword[i]; cLetter = toupper(cLetter); //convert to uppercase, so this works for both uppercase and lowercase letters strOutput = ICAO[cLetter-'A']; cout << strOutput << endl; } cin.get(); cin.get(); return 0; }
Here is my assignment. "You were first asked ot write a program that inputs a string and then ouput the corresponding words in the international Civil Aviation Organization alphabet that would be used to spell it out pheontically. For that program you should have used a large switch statement. Rewrite that program using an array of strings to hold the words of the alphabet, and index the array by the positions of the letters of the alphabet. By using an index with semantic content, you can avoid the need for the case statement. Be sure that you don't try to index into the array using non-alphabetic characters, as that will result in an out-of-bounds access. "
also i am getting one warning c:\Documents and Settings\Emily Adams\My Documents\Visual Studio Projects\Assignment11\assignment12.cpp(20): warning C4018: '<' : signed/unsigned mismatch
cout << "Input a word to return in ICAO form: " << endl;
string icaoword; cin >> icaoword;
for(int i=0; i < icaoword.length(); ++i) { std::string strOutput; char cLetter; cLetter = icaoword[i]; cLetter = toupper(cLetter); //convert to uppercase, so this works for both uppercase and lowercase letters strOutput = ICAO[cLetter-'A']; cout << strOutput << endl; } cin.get(); cin.get(); return 0; }
Here is my assignment. "You were first asked ot write a program that inputs a string and then ouput the corresponding words in the international Civil Aviation Organization alphabet that would be used to spell it out pheontically. For that program you should have used a large switch statement. Rewrite that program using an array of strings to hold the words of the alphabet, and index the array by the positions of the letters of the alphabet. By using an index with semantic content, you can avoid the need for the case statement. Be sure that you don't try to index into the array using non-alphabetic characters, as that will result in an out-of-bounds access. "
cout << "Input a word to return in ICAO form: " << endl;
cin >> icaoword;
for(int i = 0; i < icaoword.length(); i++ ) { std::string strOutput; char cLetter; cLetter = icaoword[i]; cLetter = toupper(cLetter); //use this to convert to uppercase, so it deciphers between lower and upper strOutput = ICAO[cLetter-'A']; cout << strOutput << endl; } cin.get(); cin.get(); return 0; }
Here is what I have left to fix, but I am stuck.. I can't get it in correctly """Your index on the array should be type int. Also you should check to make sure that the index value was between 0 and 25. That is the index can not be negative or greater than 25. """"
if I change it to int I get an error but it still works, so I may just leave it not sure... the error is posted a few post up I changed in this version of the code to make the warning go away, but I believe I am being told to leave the for (int i ....) as is
If you are told to leave it at int then maybe you should leave it at int. It is only a warning because string::size_type is guaranteed to hold the length of any string. In your case i don't think it will matter as your strings are not very long. Just change it to unsigned int. It's still int, so i suppose that will not make a difference to your assignment.