The assignment I am working on is asking me to input a number N
, and then to input N
strings and to check how many characters 'a'
'e'
'i'
'o'
'u'
and 'A'
'E'
'I'
'O'
'U'
are in each string and then to print it out. However, when the last string in the array starts with one of those characters, the program won't count the first letter of it, for some reason.
For example, this input:
3
This is a test
Hey Joe
I like pancakes
will have the output:
4
3
5
instead of:
4
3
6
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
int N,i,j,brojac=0;
vector<string> recenice;
string pom;
cin>>N;
for(i=0;i<N;i++){
cin.ignore();
getline(cin, pom);
recenice.push_back(pom);
}
for(i=0;i<recenice.size();i++){
for(j=0;j<recenice[i].size();j++){
if(recenice[i][j]=='a' || recenice[i][j]=='e' || recenice[i][j]=='i' || recenice[i][j]=='o' || recenice[i][j]=='u' || recenice[i][j]=='A' || recenice[i][j]=='E' || recenice[i][j]=='I' || recenice[i][j]=='O' || recenice[i][j]=='U') ++brojac;
}
cout<<brojac<<endl<<endl;
brojac=0;
}
return 0;
}
What is the cause of the counter not counting the first character of the last string if it fulfills the condition?