Need help with Pig Latin

Hi to everyone!

I'm trying to make a code that converts English to Pig Latin but i can't seem but i don't know how to add "-way" to a word if that word has no vowels.

the program should be like this:

write a prog. that prompts the user to input a string and then converts the string into Pig Latin form. the rules for converting a string into Pig Latin form are as follows:

a. if the first letter of the word is a vowel, add "-way".
b.if the first letter does not begin with a vowel, first add "-" at the end then rotate the string one character at a time until the first letter becomes a vowel. then add "ay" at the end.
c."y" can be considered a vowel so if the user inputs "by", the pig latin should "y-bay".
d.if the word does not contain any vowel, add "-way" at the end.

a, b, and c is already done but i can't figure out how to do d.

here's my program:
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
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
using namespace std;


main()
{
    int x=0, y=0;
    string word, another, vow = "aeiouy", quit="q";

    cout<<"Press q to quit\n\n";

    while(word!=quit)
    {
    cout<<"\n[lowercase letters only]\nInput word to be translated: ";
    cin>>word;

     if(word==quit)
        exit(EXIT_SUCCESS);

    another=word;

    for(x=0; x<6; x++)
    {
        if(word[0]==vow[x])
        word.insert(word.length(), "-way");
    }
    
    
    if(word[0]!= 'a' || word[0] != 'e' || word[0] != 'i'|| word[0] != 'o'|| word[0] != 'u' || word[0] != 'y')
    {
        word.insert(word.length(), "-");
        for(x=0; x<6; x++)
        {
        if(word[0]==vow[x])
            word.erase(word.length()-1,1);
        }
    }

    x=0;
    while(word[0]!= vow[x])
    {
    x++;
    if(x>6)
    {
    rotate(word.begin(), word.begin()+1, word.end());
    x=0;
    }
    }

    if(word[word.length()-1] != 'y')
        word.insert(word.length(), "ay");

    cout<<"\nThe Pig Latin of "<<another<<" is: "<<word<<endl;
}
}



and this is for d:
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
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;

main()
{
    int x=0, y=0, j=0;
    string word;

    cout<<"Word: ";
    cin>>word;

    while (y < word.length()-1)
    {
     y++;
     if(word[y] != 'a' || word[y] != 'e' || word[y] != 'i' || word[y] != 'o'|| word[y] != 'u'|| word[y] != 'y')
            {
            if(y==word.length()-1)
                word.insert(word.length(), "-way");
            }
    }


    cout<<"Word = "<<word<<endl;
}


but even if the word has a vowel It stills add "-way". please help me. advance thanks to everyone.
You have several problems:

1) Line 16: Your increment is misplaced. You start with y=0, then increment meaing the first letter you look at is word[1].
2) line 17. Any letter including a vowel, will match the condition. For example, an 'e' will return true for != 'a'. Use && instead of ||.
3) Line 19-20: You only append "-way" if you're at the end of the word, but you have no knowledge of whether you've encountered any previous vowels.

I've made a new one and it kinda works. but when i tried adding it to my prog. it get's screwed.

prog. for d:

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
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;

main()
{
    int x=0, y=0, j=0;
    string word;

    cout<<"Word: ";
    cin>>word;

    while (y != word.length())
    {
     if(word[y] == 'a' || word[y] == 'e' || word[y] == 'i' || word[y] == 'o'|| word[y] == 'u'|| word[y] == 'y')
        j++;

    y++;
    }
    if(y==word.length())
    {
    if(j == 0)
        word.insert(word.length(), "-way");
    }

    cout<<"Word = "<<word<<endl;
}


when i tried adding it to the first:
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
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
using namespace std;


main()
{
    int x=0, y=0, j=0;
    string word, another, vow = "aeiouy", quit="q";

    cout<<"Press q to quit\n\n";

    while(word!=quit)
    {
    cout<<"\n[lowercase letters only]\nInput word to be translated: ";
    cin>>word;

     if(word==quit)
        exit(EXIT_SUCCESS);

    another=word;

    while (y != word.length())
    {
     if(word[y] == 'a' || word[y] == 'e' || word[y] == 'i' || word[y] == 'o'|| word[y] == 'u'|| word[y] == 'y')
        j++;

    y++;
    }

    for(x=0; x<6; x++)
    {
        if((word[0]==vow[x]) || (j==0))
        word.insert(word.length(), "-way");
    }

    if(word[0]!= 'a' || word[0] != 'e' || word[0] != 'i'|| word[0] != 'o'|| word[0] != 'u' || word[0] != 'y')
    {
        word.insert(word.length(), "-");
        for(x=0; x<6; x++)
        {
        if(word[0]==vow[x])
            word.erase(word.length()-1,1);
        }
    }

    x=0;
    while(word[0]!= vow[x])
    {
    x++;
    if(x>6)
    {
    rotate(word.begin(), word.begin()+1, word.end());
    x=0;
    }
    }


     if(word[word.length()-1] != 'y')
        word.insert(word.length(), "ay");

    if(y==word.length())
    {
    if(j == 0)
        word.insert(word.length(), "-way");
    }


    cout<<"\nThe Pig Latin of "<<another<<" is: "<<word<<endl;
}

system("pause");
}


some words would crash. any idea why?
Topic archived. No new replies allowed.