I am having problems entering a sentence for translating into pig latin. It is set up now to read the entire sentence as one word. I would like to know how to look at each word in the sentence so that each word is translated to Pig latin seperately. Attached is my code: Thank you for your time.
the out put for hello world comes out :ello worldhay
I want it to say: ellohay orldway
// testpig.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
bool isVowel(char ch);
string rotate(string pStr);
string pigLatinString( string pStr);
int main ()
{
const int LENGTH = 100;
char str [LENGTH];
string word, result;
cout << "Enter a string or, blank to exit." <<endl;
cout << "The program will output the words in Pig Latin."<<endl;
cin.getline(str ,LENGTH);
cout<<endl;
cout << "The pig Latin form of " << str <<" is:\n"<< pigLatinString( str) << endl;
return 0;
/* Process the input line word by word */
};
bool isVowel(char ch)
{
switch (ch)
{
case 'A': case 'E':
case 'I': case 'O':
case 'U':
case 'a': case 'e':
case 'i': case 'o':
case 'u':
return true;
default: return false;
};
}//end isVowel
string rotate(string pStr)
{
string::size_ty pe len=pStr.length ();
string rStr;
rStr=pStr.subst r(1,len-1)+pStr[0];////
return rStr;
}
string pigLatinString( string pStr)
{
string::size_ty pe len;
bool foundVowel;
string::size_ty pe counter;
if (isVowel(pStr[0]))
pStr=pStr+"way" ;
else
{//didn't start with a vowel
pStr = pStr + "";
pStr=rotate(pSt r);
len=pStr.length ();
foundVowel=fals e;
for (counter = 1; counter<len-1; counter++)
if (isVowel(pStr[0]))
{
foundVowel=true ;
break;
}
else
pStr=rotate(pSt r);
if (!foundVowel)
pStr=pStr.subst r(1,len)+"way";
else
pStr = pStr + "ay";
}
return pStr;
}
the out put for hello world comes out :ello worldhay
I want it to say: ellohay orldway
// testpig.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
bool isVowel(char ch);
string rotate(string pStr);
string pigLatinString( string pStr);
int main ()
{
const int LENGTH = 100;
char str [LENGTH];
string word, result;
cout << "Enter a string or, blank to exit." <<endl;
cout << "The program will output the words in Pig Latin."<<endl;
cin.getline(str ,LENGTH);
cout<<endl;
cout << "The pig Latin form of " << str <<" is:\n"<< pigLatinString( str) << endl;
return 0;
/* Process the input line word by word */
};
bool isVowel(char ch)
{
switch (ch)
{
case 'A': case 'E':
case 'I': case 'O':
case 'U':
case 'a': case 'e':
case 'i': case 'o':
case 'u':
return true;
default: return false;
};
}//end isVowel
string rotate(string pStr)
{
string::size_ty pe len=pStr.length ();
string rStr;
rStr=pStr.subst r(1,len-1)+pStr[0];////
return rStr;
}
string pigLatinString( string pStr)
{
string::size_ty pe len;
bool foundVowel;
string::size_ty pe counter;
if (isVowel(pStr[0]))
pStr=pStr+"way" ;
else
{//didn't start with a vowel
pStr = pStr + "";
pStr=rotate(pSt r);
len=pStr.length ();
foundVowel=fals e;
for (counter = 1; counter<len-1; counter++)
if (isVowel(pStr[0]))
{
foundVowel=true ;
break;
}
else
pStr=rotate(pSt r);
if (!foundVowel)
pStr=pStr.subst r(1,len)+"way";
else
pStr = pStr + "ay";
}
return pStr;
}
Comment