help with piglatin program

Hey guys I'm new here and I just wanted some help on my Pig-Latin program. The program basically converts a word into Pig-Latin. If the word starts with a vowel, it just adds "-yay" to the end of it. If it starts with a consonant, however, it takes everything before the first vowel and puts it at the end of the word then adds "ay". For example:
is = is-yay
there = ere-thay
monkey = onkey-may
etc...

So far I have the vowels done. I can translate any word that starts with a vowel easily. The problem is with words that start with a consonant. I know it has to do with the commands, find_first_of, substr(), etc. but I'm not sure what to do.


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
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

inline bool isvowel(char c)
{
    bool vowel;
    switch(toupper(c))
    {
        case 'E': case 'A': case 'U': case 'O': case 'I': case 'Y':
        {
            vowel = true;
        }
        break;
        default:
        {
            vowel = false;
        }
    }
    return vowel;
}

int main(void)
{
    string word;
    string::size_type cons;
    const string vowels = "aeiouAEIOU";
    
    cout << "\n\t\tWelcome to the Pig-Latin Word Conversion Program. \n\n";
    cout << "Please enter a word: ";
    cin >> word;
    
    
    if(isvowel(word[0]))
    {
        cout << "\nThe translation for that in Pig-Latin would be "
             <<word<<"-yay.\n\n";
    }
    else
    {
//SOMETHING NEEDED HERE FOR CONSONANT CONVERSION
        cout << "\nThe translation for that in Pig-Latin would be ";           
    }   
    
    return 0;
}




thanks alot guys.
Last edited on
anyone please?
Im no good with strings, so ill just say edit your post with code tags and put tabs to make it easier to read.
ok i jsut edited it. yea im not good with strings either lol thats why i'm here. thanks for looking though
well, im not sure what functions to use and stuff but here some psuedo code lol

1
2
3
4
get the first letter of word and store it in storage( storage is a string or char, idk lol )
remove the first letter from word
add -yay to the end of word
add storage in 4 letters from the end of word


Im sure theres some functions that could do that.
Look at C++ string class methods to see if they can help you on your program.

http://www.cplusplus.com/reference/string/string/
sohguanh trust me i've looked at it for several hours haha. i just can't figure it out for some reason..... and thanks nano for that , that's exactly what i need. i just don't know how to code that
I would look at the modifiers on that page sohguanh linked if i were you.

and by look at i mean click on them and see how they work.
Last edited on
ive been looking at it for about 30 minutes i'll try to write a code, i'll report back
yea wow i tried to do word.find_first_of(vowels) but it won't run.... i have no idea what to do.
please anyone
1
2
3
4
5
6
7
8
9
10
11
12
//SOMETHING NEEDED HERE FOR CONSONANT CONVERSION

size_t found=word.find_first_of("aeiou");
if (found!=string::npos) {
  string word2(word.substr(found,word.length()));
  word2 += "-";
  word2 += word.substr(0,found);
  word2 += "ay";

  cout << word2 <<"\n";
} else cout << "\nThe translation for that in Pig-Latin would be "<<word<<"\n";
wow sohguanh u are a savior.. there's still one problem with it though.

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
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

inline bool isvowel(char c)
{
    bool vowel;
    switch(toupper(c))
    {
        case 'E': case 'A': case 'U': case 'O': case 'I': case 'Y':
        {
            vowel = true;
        }
        break;
        default:
        {
            vowel = false;
        }
    }
    return vowel;
}

int main(void)
{
    string word; 
    cout << "\n\t\tWelcome to the Pig-Latin Word Conversion Program. \n\n";
    cout << "Please enter a word: ";
    cin >> word;
    
    
    if(isvowel(word[0]))
    {
        cout << "\nThe translation for that in Pig-Latin would be "
             <<word<<"-yay.\n\n";
    }
    else
    {
       size_t found=word.find_first_of("aeiou");
        if (found!=string::npos) 
        {
            string word2(word.substr(found,word.length()));
            word2 += "-";
            word2 += word.substr(0,found);
            word2 += "ay";

            cout << word2 <<"\n";
         } else cout << "\nThe translation for that in Pig-Latin would be "<"ay";           
    }   
    
    return 0;
}




there are 3 errors on line 49 which is the line with the else cout.
error: no match for 'operator<' in 'std::operator<<
error: note: candidates are: operator<(const char*, const char*)<build-in>
error: operator<(void*, void*)<build-in>

it seems like everything is good except for line 49. i really appreciate it though

actually it works perfectly now. u are srsly a savior.....
Do not just copy and paste and submit. Look at how the string member functions are used. There are other ways to do also. I uses += I could have used append(....) as well but the idea is you need to look at documentation and learn.

I understand you have stared at it for hours so hopefully you get the 'hang of it'. You need them if you intend to focus on programming as your full-time job in future.
Topic archived. No new replies allowed.