Pig Latin Program Help

So I'm supposed to write a pig-latin translator. The program must be able to translate entire phrases into pig latin, output the number of letters characters and words, and if the first letter of the input is capitalized, the first letter of the output should be capitalized as well. I think I've got most of it, but I'm having trouble making the actual pig latin part of it. Any help would be appreciated. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

//function declarations
void pigLatin(char [], int word, int letter, int character);

string moveLetter(string);

bool isVowel(char);

int main()
{
	int word = 1, letter = 2, character = 2;	//variable declarations
    char phrase[100];
	
    cout << "Enter a word/phrase to translate: ";
    cin.getline(phrase,100);
 
    char *strWord;
    strWord = phrase;

	pigLatin(strWord, word, letter, character);
    cout << endl;
 
    return 0;
}
 
void pigLatin(char strWord[], int word, int letter, int character)
{
	int purple = 0;								//purple is used for making the first letter of the output capitalized if the first letter of the input is also capitalized
	for (int i = 0; i < strlen(strWord); i++)
	{
		if(isalpha(strWord[i]))			//for loop for counting words, characters (not including spaces), and letters
			letter++;
		else if(isupper(strWord[i]))
			purple = 1;
		if(!isspace(strWord[i]))
			character++;
		if(isspace(strWord[i]))
			word++;
	}
	moveLetter(strWord);
	if(purple = 1)
		strWord[0] = toupper(strWord[0]);

	cout << strWord << "ay\nThere are " << letter  << " letters\nThere are " << word << " words\nThere are " << character << " characters" << endl; 

}
 
string moveLetter(string strWord)
{
    if (!isVowel(strWord[0])) 
	{
        char chLetter = strWord[0];
        return moveLetter(strWord.substr(1) + chLetter);	//changes the phrase to pig latin while checking for vowels
    }
    else 
		return strWord; 
}
 
bool isVowel(char chLetter)
{
    char letters[] = {'a','e','i','o','u'};		//function used for determining if the letter is a vowel
 
    for (int i = 0; i < 6; i++) 
	{
        if (tolower(chLetter) == letters[i]) 
			return true;
    }
    return false;
}
Last edited on
Topic archived. No new replies allowed.