Start New Discussion within our Software Development Community

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;
	cin>>sentence;
	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;
	else
		return false;
}

>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 ) )
      ++vowels;
  }

  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 article has been dead for over six months. Start a new discussion instead.