#include<iostream>
#include <cctype>
#include<string>
usingnamespace std;
int main()
{
int Choice;
string word;
cout << "Enter your choice: ";
cin >> Choice;
cout << "Enter a word: ";
cin >> word;
int vowelCount = 0;
int numLetters = word.length(); //get the number of letters in a word
char letter; //a letter in a word
for (int i = 0; i < numLetters; i++)
{
letter = word[i]; //get the (i+1)th letter in the word
if(letter == 'a' || letter == 'e'||
letter == 'i' || letter == 'o'||
letter == 'u' || letter == 'y')
{
vowelCount ++;
cout << "word contains " << vowelCount << "vowels." << endl;
if (isupper(letter))
cout << "there are " << vowelCount << "upper case vowels" << endl;
}
}
return 0;
}
Ignore the Choice part please... This is originally a void function I wrote. I also need to write different functions about converting words to upper/lower cases, extracting number of letters, etc.
But before I do that, I just want to completely understand how word length and upper case works...
And my program is not working at all!!! Could you please show me the changes I need to make and tell me the reasons? thank you soooooooo much!
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string text, text2;
cout << "Enter some text. ";
getline (cin, text);
if (text.find_first_of("aeiou") == string::npos)
{
cout << "The text entered does not contain vowels!"
<< endl;
}
else
cout << "\nThis has at least one vowel. " << endl;
cout << "\nEnter some text. ";
getline (cin, text2);
if (text2.find_first_of("AEIOU") == string::npos)
{
cout << "\nThe text entered does not contain any uppercase vowels!"
<< endl;
}
else
cout << "\nThis has at least one upper case vowel. " << endl;
return 0;
}