I have a program that compiles and runs fine, I am having problems with the output. The program takes a group of words and translates them into pig latin. It should read:
Enter a group of words or ENTER to quit: Hello Daddy Jim
Original Words: Hello Daddy Jim
New Words: elloHay addyDay imJay
But this is what comes out:
Enter a group of words or ENTER to quit: Hello Daddy Jim
Original Words: Hello Daddy Jim
Hello
Daddy
New Words: elloHay addyDay imJay
I know it has to be something stupid, but I have been working on this for hours and cannot seem to find the problem. Any suggestions?
// Display heading
cout << "**************************************************\n";
cout << "*** You will be prompted to enter a string of ***\n";
cout << "*** words. The string will be converted into ***\n";
cout << "*** Pig Latin and the results displayed. ***\n";
cout << "*** Enter as many strings as you would like. ***\n";
cout << "**************************************************\n";
// While condition is true loop
while(true)
{
// Prompt user to enter a group of words or quit
cout << "\nEnter a group of words or ENTER to quit: ";
getline(cin, str);
// Break loop if string is empty
if(str.length() == 0)
break;
// Display original words
cout << "Original words: " << str << endl;
// Display pig latin words
cout << "New Words: " << PigLatinString(str) << endl;
}
return 0;
}
// PigLatinString function
string PigLatinString(string pigString)
{
// Declare function string variables
string::size_type len = pigString.length();
string::size_type counter();
string::size_type start = 0;
string::size_type begin = 0;
string phrase, newString = "";
phrase = pigString.substr(begin, pigString.length() - begin);
On another note, I am really trying to develop good habits when writing the programs. Any comments or suggestions on the content or comments written in the program are welcomed. The Professor only seems concerned on the program working and not the layout or substance of the program. Thanks!