Wondering if this works...

I am writing a program of checking how many vowels are in one word and the uppercase vowels in that word...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<iostream>
#include <cctype>
#include<string>

using namespace 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;
}
so what is your question?
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!
You could do something like this. The program continues to search until it finds an instance of
of a vowel.

example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    #include <iostream>
#include <string>

using namespace 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;
}
Last edited on
Thank you very much!
Topic archived. No new replies allowed.