count vowel problems

whatever i do my programmer giving the same output and not counting my input where is my problem ?
my goal is the get this
Sample Input
2
Sa zanore ka
Po kjo fjali sa zanore ka
and get this
Sample Output
5
9

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>
using namespace std;
bool isVowel(char ch)
{if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='y')
return true;
else return false;
}
int main()
{int T,i,m,t,cut=0;
string S;
char ch;
cin>>T; 
for (T=1 ; T<= 2  ; T++ )
{
for(t=1;t<=T;t++)
{getline(cin,S);
m=S.length();
for(i=0;i<m;i++)
ch=tolower(S[i]);
if(isVowel(ch))
cut++;
}
}
cout<<cut<< endl;
return 0;
}
Your code properly indented
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
#include <iostream>
#include <string>
using namespace std;
bool isVowel(char ch)
{
	if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='y')
		return true;
	else return false;
}
int main()
{
	int T,i,m,t,cut=0;
	string S;
	char ch;
	cin>>T; 
	for (T=1 ; T<= 2  ; T++ ) //so you discarded what you just readed
	{
		for(t=1;t<=T;t++)
		{
			getline(cin,S); //S is probably empty (if you leave a '\n' in the buffer)
			m=S.length();
			for(i=0;i<m;i++) //useless loop
				ch=tolower(S[i]);
			if(isVowel(ch)) //checking only the last character
				cut++;
		}
	}
	cout<<cut<< endl;
	return 0;
}
for your isVowel you can also simply put this:

 
return( ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='y' );


and honestly I am having a hard time following what you are trying to do for lines 16 and after..

Basically what you want to do is read a string in. Loop for the entire string and if it is a vowel increase by one. Also you should try more descriptive names so people know what they are (exception: for loops i , ix , j , ect.. are used often for indexes )
you will need to use getline(cin,string); other wise if you do cin>>string , your variable will only store characters up to the space character.

Also, I recommend using substring from the library string.
He did use getline. The operator >> was for some integer that who know's what it is for.
Topic archived. No new replies allowed.