I am trying to get this code working for extra credit, but I unfortunately only have 40 minutes until it is due:rolleyes:. I would like to know how to do this program, whether I turn it in or not. The letter "Y" can be considered a vowel if there is not a vowel immediately before or immediately after the "y", otherwise it should be considered a consonant. I have everything working except for the Y being counted as a vowel when it is next to consonants.
#include <iostream>
#include <cctype>
using namespace std;
int Y(char string[], int ctr, int vowel);
int length = 0;
int vowel = 0;
int main()
{
char string[50] = "";
cout << "Please enter a string of 50 characters or less: ";
cin.getline(string, 50);
length = strlen(string);
for(int ctr = 0; ctr < length; ctr++)
{
string[ctr] = tolower(string[ctr]);
if(string[ctr] == 'a' || string[ctr] == 'e' || string[ctr] == 'i' || string[ctr] == 'o' || string[ctr] == 'u')
{
vowel++;
if(string[ctr] == 'y')
{
vowel = Y(string, ctr, vowel);
}
}
if(string[ctr] == ' ')
{
vowel++;
}
}
cout << "\nThe string you entered was: "<< string << endl;
cout << "You entered " << (length - vowel) << " consonants in that string." << endl;
}
int Y(char string[], int ctr, int vowel)
{
bool flag1 = false;
bool flag2 = false;
if(string[ctr++] == 'a' || string[ctr++] == 'e' || string[ctr++] == 'i' || string[ctr++] == 'o' || string[ctr++] == 'u')
{
flag1 = true;
}
if(string[ctr--] == 'a' || string[ctr--] == 'e' || string[ctr--] == 'i' || string[ctr--] == 'o' || string[ctr--] == 'u')
{
flag2 = true;
}
if((flag1 == true) && (flag2 == true))
{
vowel--;
}
return vowel;
}