Translator to Pig latin program

So I've been trying to implement a program that translates a word/sentence (inputed by the user) from english into pig latin and vice versa. A Pig Latin word is formed from an English word by stripping the initial consonants from the front of the word and tacking them on the end with the addition of "ay". We ad a '-' so that it can be reversed. For example, "pig latin" in pig latin would be "ig-pay atin-lay". I cannot use string.substr for this homework and am confused on getting the input line. The first part of the homework says to pull characters out of the input line until you hit a space (or end of line), keep a counter of how much of the line you have read, so you know where to start for the next word, then take each single word to the next part, repeat this (do in a loop) until you use up the whole line. Then it asks to translate from english to piglatin. To do this it says: Within a word, copy characters (use a loop) into some string until you hit a vowel. The rest of the original word can be printed out. (This could also be a loop, character by character, if you don't know a way to refer to the string with the first few characters chopped off). Then print the copied string, and add "ay". This is what I have so far, but it's kind of all over the place. Any help would be much appreciated. Thank you.

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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
#include <string>
using namespace std;

void count (string text)
{
    int count = 0;
    while (text[i] != ' ' && i < text.size())
    {
        i++;
    }
    /*for (int i = 0; i > text.size(); i++)
    {
        char character = text[i];
        if (character == ' ')
        {
            count--;
        }
        while (character != ' ')
        {
            count++;
        }
    }*/
}
  string pigLatin (string text)
{
    for (int i = 0; i < 1; i++)
    {
        char letter = text[i];
        char nextLetter = text[i+1];
        char temp = letter;
        letter = nextLetter;
        temp = tolower(temp);
        nextLetter = temp;
        cout << letter << nextLetter;
    }
    
    cout << endl;
    return text;
}

string english (string text)
{
    for (int i = 0; i < text.size(); i++)
    {
        char character = text[i];
        if (character == 'A' || character == 'E' || character == 'I' || character == 'O' || character == 'U' || character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u')
        {
            text[i+1] = '-';
        }
    }
    return text;
}

int main()
{
    cout << "Welcome to Pig Latin" << endl;
    cout << "1: to Pig Latin" << endl;
    cout << "2: to English" << endl;
    cout << "3: quit" << endl;
    int option;
    cin >> option;
    
    if (option == 1)
    {
        cout << "enter text to translate :" << endl;
        string text;
        cin.ignore();
        getline(cin, text);
        cout << pigLatin(text) << endl;
    }
    
    if (option == 2)
    {
        cout << "enter text to translate :" << endl;
        string text;
        cin.ignore();
        getline(cin, text);
        cout << english(text) << endl;
    }
    
    if (option == 3)
    {
        cout << "Press any key to continue";
    }
    
    while (option > 3)
    {
        cout << "Invalid option" << endl;
        
        cout << "Welcome to Pig Latin" << endl;
        cout << "1: to Pig Latin" << endl;
        cout << "2: to English" << endl;
        cout << "3: quit" << endl;
        int option;
        cin >> option;
        
        if (option == 1)
        {
            cout << "enter text to translate :" << endl;
            string text;
            cin.ignore();
            getline(cin, text);
            cout << pigLatin(text) << endl;
        }
        
        /*if (option == 2)
         {
         cout << english(text) << endl;
         }*/
        
        if (option == 3)
        {
            cout << "Press any key to continue";
        }
    }
    
    return 0;
}
Topic archived. No new replies allowed.