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.
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
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
//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";
#include <iostream>
#include <string>
#include <cctype>
usingnamespace std;
inlinebool 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
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.