Got a problem with the exclamation point not moving to the end in the pig latin program. Shows up as earn!lay

#include <iomanip>
#include <iostream>
#include <string>

const int Characters = 100;
char Sentence [Characters] = {'\0'};
void pigLatinString ();
size_t pos = 0;

using namespace std;

int main ()
{
cout << "*********************************************" << endl;
cout << "* You will be prompted to enter a string of *" << endl;
cout << "* words. The string will be converted into *" << endl;
cout << "* Pig Latin and the results displayed. *" << endl;
cout << "* Enter as many strings as you would like. *" << endl;
cout << "*********************************************" << endl << endl;

cout << "Enter a group of words or ENTER to quit: ";
cin.getline(Sentence, 100, '\n');
cout <<endl;

while (Sentence[0] !='\0')
{
cout << "Original Words: " << Sentence << endl;
cout << "New Words: ";
pigLatinString();
cout << endl;
cout << "Enter a group of words or ENTER to quit: ";
cin.getline(Sentence, 100, '\n');
}
return 0;
}


void pigLatinString ()
{
char tempConstant [10];
tempConstant [0] = '\0';
int numberOfConstants = 0;
char previousCharacter = ' ';
char currentCharacter = ' ';
bool Word = 0;


for (int i = 0; i < Characters; i++)
{
if ( Sentence[i] == '\0')
{
if (Word)
{
if (previousCharacter != ' ')
cout << tempConstant << "ay" << endl;
}

return ;
}


if (Word)
{
if (Sentence[i] == ' ')
{
cout << tempConstant << "ay";
Word = 0;
tempConstant [0] = '\0';
numberOfConstants = 0;
}
cout << Sentence[i];

}
else
{
if (Sentence[i] != ' ')
{
char currentCharacter = Sentence[i];
currentCharacter = toupper( currentCharacter);


if ((currentCharacter != 'A') && (currentCharacter != 'E') &&
(currentCharacter != 'I') && (currentCharacter != 'O') && (currentCharacter != 'U'))

{
tempConstant [numberOfConstants] = Sentence[i];
tempConstant [numberOfConstants + 1] = '\0';
numberOfConstants++;
}
else
{
Word = 1;
cout << Sentence[i];
}
}
else
{
cout << Sentence[i];
}
}

previousCharacter = Sentence[i];
}
return ;
}
I don't see where you are printing !, so it must be part of the string the user inputs.

I don't see where you look for a matching ! and move it to the end.

and last but not least, your code is not formated and makes it darn hard to read. Learn to use code tags.

http://www.cplusplus.com/articles/jEywvCM9/

Topic archived. No new replies allowed.