First, why can I not get this code to highlight and format to code tags?
Second, can anyone show me how to make this code display correctly when it runs
??????
//Write a program that inputs a letter and outputs the corresponding I.C.A.O. alphabet word.
//Turn the program into a function, use it to convert to a string input by the user into the series
//of words that would be used to spell it out phonetically.
#include <iostream>
#include <string>
usingnamespace std;
void convert(string);
int main()
{
string input;
// Prompt user to input
cout << "Enter string:";
cin >> input;
cout<< "Phonetic version is:";
convert(input);
cout<<endl;
system ("pause");
}
//create function
void convert(string input)
{
int i=0;
//declare variables
char letter;
int length=input.length();
//while loop
while (i<length)
{
letter=input.at(i);
//all instances of letters
if(letter='a'|| letter=='A')
cout <<"Alpha";
elseif (letter==' b '|| letter=='B ')
cout <<" Bravo ";
elseif (letter==' c '|| letter==' C ')
cout <<" Charlie ";
elseif (letter==' d '|| letter=='D ')
cout <<"Delta ";
elseif (letter==' e '|| letter==' E ')
cout <<" Echo ";
elseif (letter==' f '|| letter==' F ')
cout <<" Foxtrot ";
elseif (letter==' g '|| letter==' G ')
cout <<" Golf ";
elseif (letter==' h '|| letter=='H ')
cout <<" Hotel ";
elseif (letter==' i'|| letter==' I ')
cout <<" India ";
elseif (letter==' j '|| letter==' J ')
cout <<" Juliet ";
elseif (letter==' k '|| letter==' K ')
cout <<" Kilo ";
elseif (letter==' l '|| letter==' L ')
cout <<" Lima ";
elseif (letter==' m '|| letter==' M ')
cout <<" Mike ";
elseif (letter==' n '|| letter==' N ')
cout <<" November ";
elseif (letter==' o '|| letter==' O ')
cout <<" Oscar ";
elseif (letter=='p '|| letter==' P ')
cout <<" Papa ";
elseif (letter==' q '|| letter==' Q ')
cout <<" Quebec ";
elseif (letter=='r '|| letter==' R ')
cout <<" Romeo ";
elseif (letter==' s '|| letter==' S ')
cout <<" Sierra ";
elseif (letter==' t '|| letter==' T ')
cout <<"Tango ";
elseif (letter==' u '|| letter==' U ')
cout <<"Uniform ";
elseif (letter==' v '|| letter=='V ')
cout <<"Victor ";
elseif (letter==' w '|| letter==' W ')
cout <<" Whiskey ";
elseif (letter==' x '|| letter==' X ')
cout <<" X-ray ";
elseif (letter==' y '|| letter==' Y ')
cout <<" Yankee ";
elseif (letter==' z '|| letter=='Z ')
cout <<"Zulu ";
i++;
}
}
[code]Put your code here between the code tags for it to show up properly.[/code]
As for your second question, letter is supposed to be a char. Stuff like ' c ' is not a char because it does not have a length of 1. I hesitate to call it a string because you're using single quotes, not double quotes. I have no idea what to call it, but in any case, it is not a char.
No, i'm saying that you should take out all those spaces in your comparisons. Instead of letter==' c ', it should be letter=='c'. That applies for all the comparisons you have.
Sorry, but that just doesn't seem possible. If you have a space at the end of each phonetic word in the list and no newlines, it would be impossible for the words to run together. I'm thinking you removed the newlines, but did not put a space at the beginning of the word, or instead, at the end. One or the other, not both, or you'll have two spaces between words. I ran your program with these corrections as I described, and got the correct results of space words