value-returning function

Write a value-returning function, isVowel( ), that returns the value true if a given character
is a vowel and otherwise returns false. Using function isVowel( ), write a program that
prompts the user to input a sequence of characters and outputs the number of vowels. ?


#include <iostream>

using namespace std;

bool isvowel()
{

char x ;

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



}



int main()


{

int NumOfVowels=0 ;
char x ;

bool flag;



cout << "Enter a sequance ?" ;
cin >> x ;




for ( flag==false ; flag==false ; flag++ )

{

if ((x=='a' )||(x == 'u')||(x=='e')||(x=='o')||(x== 'i') )
{
isvowel() ;




NumOfVowels++;

}



}


cout << NumOfVowels ;


return 0 ;




}




please help me when i enter a sequence of characters it reads the first character only and give me one

i dont know where is the problem !!!


i use code blocks


thank you
Hi Teemo,

First, initialize your variables because you are using them before give them a value and revise the parameters of your isvowel() function.
You should use string instead of char and use a for-loop to go through the string to count how many vowels the user entered.
thank you mr-krugle ,


but when i use string it gives me an error in


if ((x=='a' )||(x == 'u') || (x=='e') || (x=='o')|| (x== 'i') )
Write a value-returning function, isVowel( ), that returns the value true if a GIVEN character


I read this as make your method one of these:

bool isvowel(char vowelToCheck)

Or how are you going to check each character??
i already did this function
the problem is how to check each character
because i think it checks the first character only and give me 1 when the first character is vowel
this is the code now
#include <iostream>
using namespace std;
bool isvowel(char x) ;
int main()
{

int NumOfVowels=0 ;
char x ;

bool flag;



cout << "Enter a sequance ?" ;
cin >> x ;

for ( flag=false ; flag==false ; flag++ )

{

if ((x=='a' )||(x == 'u')||(x=='e')||(x=='o')||(x== 'i') )
{
isvowel(x) ;

NumOfVowels++;

}


}


cout << NumOfVowels ;

return 0 ;

}

bool isvowel(char x)
{


if ((x=='a' )||(x == 'u')||(x=='e')||(x=='o')||(x== 'i') )

return true ;
else
return false ;

}
You do not need this check:
if ((x=='a' )||(x == 'u')||(x=='e')||(x=='o')||(x== 'i') )

twice in your code. Remove it from main() and keep it in your isvowel method.
edit: i've just properly read your question.

1. read in a STRING not a char. this is your character sequence.
2. iterate over this string and call isvowel() on each character.

You have asked the user for a sequence but are storing only a character.
Last edited on
thank you mutexe

#include <iostream>
#include <string>
using namespace std;
bool isvowel(string x ) ;

int main()
{

int NumOfVowels=0 ;
string x ;

bool flag;



cout << "Enter a sequance ?" ;

getline ( cin , x ) ;

for ( flag==false ; flag==false ; flag++ )

{



isvowel(x);

NumOfVowels++;




}


cout << NumOfVowels ;


return 0 ;


}

bool isvowel(string x )
{




if ((x =='a' )||(x == 'u')||(x=='e')||(x=='o')||(x== 'i') )

return true ;
else
return false ;

}





i searched for iteration of strings and i found that , we didnt study that method yet , so i cant use it now for the homework



and i still have an error in


if ((x =='a' )||(x == 'u')||(x=='e')||(x=='o')||(x== 'i') )


helppp me guys
Nearly there mate :)

Your isVowel method should still take a char.

give me a sec i'll knock something up.
something like this:

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>

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

		return true ;
	else
		return false ;

}



int main()
{

	std::string testString("Boobs");
	int numVowels(0);	

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

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

	std::cout << "Number of vowels in '" << testString << "': " << numVowels;
	return 0;
}
thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaank yooooou finally it works
No worries dude. You were nearly there anyway.
Topic archived. No new replies allowed.