help with functions

so i got the code right however it's telling me that the function that i am calling failed the test. which i have no idea what that means. this is the assignment.

Write a program that prompts the user to input a sequence of characters and outputs the number of vowels. Write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. Use this function to determine how many of the characters entered by the user are vowels.

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

bool isVowel(char x);

int main() {

   string testString;
	int numVowels(0);	
	
	cout << "Write a string: " ;
	cin >> testString;
	

	for(int i=0;i < (int)testString.length();++i)
	{
		char charToTest = testString.at(i);

		if(true == isVowel(charToTest))
		{
			numVowels++;
		}
	}

	cout << "Your word has " << numVowels + 1 << " vowels" << endl;
	return 0;

   return 0;
}

bool isVowel(char x){
   if ((x =='a' )||(x == 'u')||(x=='e')||(x=='o')||(x== 'i') )

		return true ;
	else
		return false ;
}
so i got the code right
I don't think so.

Output of your code:
1
2
3
Write a string: test
Your word has 2 vowels
 


By the way when I first ran your code I tried to enter this string "This is a test". Maybe you should say "Enter a word: " instead of "Write a string: ".

Topic archived. No new replies allowed.