I've been able to count number of syllables in a word by making a simple nested for loop, but can't figure out how to rewrite such an algorithm that ensures any multiple vowels right next to each other in a word count as just one syllable. I've only come across one other example using pointers, my question is if there's any other approach as I just started learning pointers this week and am not sure how to use them properly.
This is my program so far:
#include <iostream>
#include <string>
using namespace std;
void indexfx(string sentence);
int main(void)
{
string user;
cout << "\n\nPlease Enter a Sentence: ";
getline(cin, user);
indexfx(user);
return 0;
}
void indexfx(string sentence)
{
string vowels = "aeiouy";
int syllables = 0;
for(unsigned int i = 0; i < sentence.size(); i++)
{
for(unsigned int j = 0; j < vowels.size(); j++)
{
if(sentence[i] == vowels[j]
{
syllables++;
}
}
}
cout << syllables;
}