Beginner needs a little help with isVowel value returning function program.

I've been banging my head against the wall for days now, trying to get this function to return a value. I think I'm too close, but I suspect that my isVowel function doesn't return anything. Could you take a look?

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
#include <iostream>	
#include <string>
using namespace std;
bool isVowel(char word);

int main()
{
	string word;
	int counter = 0;


	cout << "This program will observe a word or sentence and determine whether or" << endl;
	cout << "not it contains vowels, and how many vowels it contains." << endl;
	cout << "Please enter a word or sentence:" << endl;

	getline(cin, word);
	

		for (char i = 0; i != '\0'; i++)
		{
			if (isVowel(i) == 1)
				counter++;
		}

	cout << "This entry contains " << counter << " vowels." << endl;
	getline(cin, word);
	return 0;
}
bool isVowel(char word)
{	
	if (word = 'a' || 'e' || 'i' || 'o' || 'u'
		|| 'A' || 'E' || 'I' || 'O' || 'U')
		return 1;
	else
		return 0;
}
Last edited on
closed account (LA48b7Xj)
The vowel function had mistakes and also the for loop.

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
#include <iostream>
#include <string>
using namespace std;

bool isVowel(char);

int main()
{
    cout << "This program will observe a word or sentence and determine whether or" << endl;
    cout << "not it contains vowels, and how many vowels it contains." << endl;
    cout << "Please enter a word or sentence:" << endl;

    string line;
    getline(cin, line);

    int counter = 0;
    for(size_t i = 0; i < line.size(); i++)
    {
        if (isVowel(line[i]))
            counter++;
    }

    cout << "This entry contains " << counter << " vowels." << endl;
    cin >> line;
}

bool isVowel(char ch)
{
    ch = tolower(ch);

    if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
        return true;
    return false;
}

Last edited on
Thank you, thank you, thank you. I used this and put on some finishing touches to make the program useable multiple times. The result worked. Here it is.

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
39
40
41
42
43
44
#include <iostream>	
#include <string>
using namespace std;
bool isVowel(char);

int main()
{

	string line; 
	char end = 'y';

	cout << "This program will observe a word or sentence and determine whether or" << endl;
	cout << "not it contains vowels, and how many vowels it contains." << endl;
	
	while (end != '#')
	{
		cout << "Please enter a word or sentence:" << endl;
		cin.ignore();
		getline(cin, line);
		int counter = 0;

		for (size_t i = 0; i < line.size(); i++)
		{
			
			if (isVowel(line[i]))
				counter++;
		}

		cout << "This entry contains " << counter << " vowels." << endl;
		cout << "If you would like to enter another word or phrase enter any key." << endl;
		cout << "If you would like to terminate press #" << endl;
		cin >> end;
	}
	return 0;
}

bool isVowel(char ch)
{
	ch = tolower(ch);

	if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
		return true;
	return false;
}
Topic archived. No new replies allowed.