unable to find out what is wrong

I was trying to solve a problem in codeabbey.com. In this problem i have to output number of vowels per line of text.but i am not getting where my code has gone wrong.The output is always wrong.
Please can anyone explain me where i went wrong?
Its a bit urgent.
Note : the problem states that i should also take 'y' as a vowel.here is the code.

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
#include<iostream>
#include<string>
#include<cctype>

using namespace std;

bool isvowel(char c){
  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y')
    return true;
  else
    return false;
}

int main(){
  string str;
  int N,counter=0;
  cin >> N;
  while(N--){
    getline(cin,str);
	for(int i=0;i<str.size();i++)
	  if(isvowel(str.at(i))==true)
	    counter++;
	cout << counter << "  ";
	counter=0;
  }
  return 0;
}
Last edited on
Why the line 8, when line 9 uses c?
@keskiverto You are right.thats a mistake.
But even after changing it, i am getting the wrong answer.
You have problems with capital vowels. Apply tolower to the character tested in your isvowel function.
@MiiNiPaa The problem says that there would be no capital vowels in the line.
Line 17 is formatted input. It leaves newline into the stream.
Line 19 is unformatted input. The first time probably returns an empty string.

Insert between lines 17 and 18:
cin.ignore( 1, '\n' );


If you want to read all input before showing any answers, then you have to store the answers rather than print immediately.
@keskiverto Thank you very much.The code worked perfectly.And i thank cplusplus.com for providing such a forum.
I will be posting in this forum whenever i stuck in programming.
Topic archived. No new replies allowed.