Homework help

Hi, I need help on this homework assignment I'm currently on.

Design a value returning function that will expect one char type parameter. If the character is a vowel it should return true. If the character is not a vowel, it should return false. For the purposes of the function a vowel is an upper or lower case A, E, I, O, or U. To test your function, create a program that reads a series of characters from a text file via Linux redirection. The program must call the vowel checking function to test each character. As output, the program (main function) should display a message stating how many vowels were found in the file

This is my code so far:

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

bool isvowel(char x);

int main()
{

  char x;
  int count = 0;

  cin >> x;

  while(cin)
    {
      if(isvowel(x))
        {
          count++;
        }
      else
        {
          count = 0;
        }

      cin >> x;
    }
  cout << "There are " << count << " vowels" << endl;

  return 0;
}

bool isvowel(char x)
{
  if ((x=='a')||(x=='A')||(x=='e')||(x=='E')||(x=='i')||(x=='I')||(x=='o')||(x=='O')||(x=='u')||(x=='U'))
    return true;
  else
    return false;
}


The code works fine if I only type in vowels(a,e,i,o,u). However when I type in other letters in the alphabet along with vowels the program doesn't work.
Last edited on
Nevermind, I found the mistake I didn't need to include the else statement in my code.
Good for you. Please mark it as solved. And if you ever decide to post in the future, please put your code between code tags, otherwise its unreadable - http://www.cplusplus.com/articles/jEywvCM9/
Ok will do in the future! It's my first time posting.
I can see that :)

Happy Coding!
Topic archived. No new replies allowed.