I have to write code that will prompt you to input a sentence, then it will output the number of vowels in the sentence. This is what I have so far. Can someone tell me what is wrong with it?

Thanks so much!

//Input a sentence, then return number of vowels in the sentence
#include <iostream>
using namespace std;

char ch(char vowel);
char isVowel (char a, char e, char i, char o, char u);

int main ()

char sentence;
char isVowel;
int number;
	cout<<"Enter a sentence"<<endl;
	cout<<"There are "<<number<<" vowels in this sentence."<<endl;

	return 0;

char isVowel (char a, char e, char i, char o, char u)
	if (ch = 0)
		return number;
		return false;
13 Years
Discussion Span
Last Post by Narue

>Can someone tell me what is wrong with it?
Just about everything. You're also overcomplicating things and it's pretty obvious that you aren't referring to any book on C++ or trying to compile this or you wouldn't have such dreadful syntax errors.

Use this as a template:

#include <cctype>
#include <iostream>

bool is_vowel ( int ch )
  ch = std::tolower ( static_cast<unsigned char> ( ch ) );
  return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';

int main()
  char ch;
  int vowels ( 0 );

  std::cout<<"Enter a sentence: ";
  while ( std::cin.get ( ch ) && ch != '\n' ) {
    if ( is_vowel ( ch ) )

  std::cout<<"The number of vowels was: "<< vowels <<std::endl;

But I should give you fair warning. If you copy parts of my code, you'll get a failing grade because it's written to make it obvious that you didn't come up with it on your own. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.