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.