I need a bit of guidance.
I want to sharpen my skill, so I'm practicing with smaller projects.
The current challenge is to create a function that can count syllables in a user inputted word.
My thinking is to declare an array of vowels: a, e, i, o, u.
then iterate through the user inputted word, checking if any letters of the word match with the vowel array, and if yes, check if the next letter doesn't. (I'm assuming a syllable is defined by the presence of a vowel AND consonant.)
This will need nested for loops, one to iterate through the word, and then another to iterate through the vowel array with the current index of 'word'.
I haven't even figured out how I'm going to do the same for word[i+1] yet.
But I'm struggling because I can't get my program to compile due to basic errors. I should probably use a string class, but I don't know.
Here's what I've got (And it won't compile!):
#include <iostream>
char vowels[] = {'a', 'e', 'i', 'o', 'u'};
int numberOfSyllables(char *word)
{
int numberOfVowelsFound = 0;
for ( &element : word )
{
bool vowelMatch = 0;
for ( &vowel : vowels)
{
if (element == vowel)
{
vowelMatch = 1;
break;
}
}
if ((vowelMatch == 1) numberOfVowelsFound++;
}
return numberOfVowelsFound;
}
int main()
{
char *userInput[50];
std::cout << "Enter a word: ";
std::cin >> *userInput;
std::cout << numberOfSyllables(userInput) << " syllables found";
return 0;
}