I have to write a program that prompts the user to input a sequence of characters and outputs the number of vowels. The previous problem had me return true or false if inputted letter is a vowel or not so I have that.
I have looked at a bunch of other posts but they all include string.length, which I have not learned (therefore cannot use) and arrays (same thing).
This is what I have. I thought something along the lines of cin.get(ch) but can't get that working either.
string.length() will just return the number of letters in your word.
So you can use a simple for loop for this.
1 2 3 4 5 6 7 8 9 10 11 12
bool x;
int counter=0;
for (int i = 0; i < phrase.length(); i++)
{
x = isvowel(phrase[i]);
if (x == true)
{
counter++;
}
}
cout << " There are " << counter << " vowels in " << phrase << endl;
The square bracket with i just gets each letter of your phrase and checks with bool isvowel.
so if you phrase is apple. Then it will take 'a' and check it if it is vowel or not. if it is vowel, which means if bool function returns true, counter gets a +1. It does this (loops) until it checks the last character of phrase.