new poster, need help with a pig latin translator. translation doesn't work properly, any tips or troubleshoots?
sorry if it seems long...
any help would be greatly appreciated

#include <iostream>
#include <string>

using namespace std;

bool isVowel(char ch);
string rotate(string pigStr);
string pigLatinString(string pigStr);

int main () 
	char Piggy[1024];

	string str;
	cout << "Enter a string:";
	cin.getline(Piggy, 1024);
	str = Piggy;

	cout << "The pig Latin form of" << str << "is:"<< pigLatinString(str) << endl;
	return 0;

bool isVowel(char ch) 
	switch (ch) 
	case 'A': case 'E': 
	case 'I': case 'O':
	case 'U': case 'Y': 
	case 'a': case 'e':
	case 'i': case 'o': 
	case 'u': case 'y': return true;
	default: return false;
}//end isVowel

string rotate(string pigStr) 

	string::size_type len=pigStr.length();
	string rStr;
	return rStr;

string pigLatinString(string pigStr) 

	string::size_type len;

	bool foundVowel;

	string::size_type counter;
	if (isVowel(pigStr[0]))
	{//didn't start with a vowel
		pigStr = pigStr + "-";
	for (counter = 1; counter<len-1; counter++)
	if (isVowel(pigStr[0]))

	if (!foundVowel)

		pigStr = pigStr + "ay";
	return pigStr;


here is sample output

The pig Latin form ofToday is a great dayis:oday is a great day-Tay
Press any key to continue . . .
8 Years
Discussion Span
Last Post by camipr64

it seems that the program is treating the whole sentence as one word...


I think that it is important that we focus on the origins of pig latin and how it is properly implemented:

Pig Latin is a language game of alterations played in English. To form the Pig Latin form of an English word the initial consonant sound is transposed to the end of the word and an ay is affixed (for example, trash yields ash-tray and plunder yields under-play). The purpose of the alteration is to both obfuscate the encoding and to indicate for the intended recipient the encoding as 'Pig Latin'. The reference to Latin is a deliberate misnomer, as it is simply a form of jargon, used only for its English connotations as a 'strange and foreign-sounding language'; it could also be because the transformed words sound similar to Latin.

Rules and variations
The usual rules for changing standard English into Pig Latin are as follows:

In words that begin with consonant sounds, the initial consonant or consonant cluster is moved to the end of the word, and "ay" is added, as in the following examples:
beast → east-bay
dough → ough-day
happy → appy-hay
question → estion-quay
star → ar-stay
three → ee-thray
In words that begin with vowel sounds or silent consonants, the syllable "ay" is added to the end of the word.
Transcription varies. A hyphen or apostrophe is sometimes used to facilitate translation back into English. Ayspray, for instance, is ambiguous, but ay-spray means "spray" whereas ays-pray means "prays."

Edited by Clinton Portis: easonrey orfey editingday


Yeah, i got that same definition from the prof in the assignment listing, I originally used cin, but that only read up to the first space, so I used the cin.getline to attempt to fix that problem, but the program treats the entire sentence as one word, any suggestions to clean up my code?


You'll probably have to take in the entire line using getline() then parse the line up into individual words:


char* words[30];

cout << "Enter line: ";
cin.getline(swine, 100);

//break it up
int =0;
words[0] = strtok(swine, ' ');
while(swine[i] != NULL)
     words[i] = strtok(NULL, ' ');

//Now you have the ability to do something like this
for(int i=0; i<word_count; i++)

//Now copy all the pig latinized words back into a single buffer
char buffer[100];
for(int i=0; i<word_count; i++)
     strcat(buffer, words[i]);
     strcat(buffer, ' ');

Here is the documentation for strtok()

Edited by Clinton Portis: tokentastically tokenlicious.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.