Click here to Skip to main content
15,912,457 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string r;
            r = Console.ReadLine();
            int count = 0;
            char[] vow = new char[] { 'a', 'e', 'i', 'o', 'u' };
            string res = new string(vow);
            for (int x = 0; x < r.Length; x++)
            {

                if (res.Contains(r[x]))
                {
                    count++;

                }
                Console.Write("vowel count:{0}", count);
                break;
            }
Posted
Comments
Mehdi Gholam 14-Dec-14 2:02am    
... and your problem is?
Member 11287281 14-Dec-14 2:10am    
yeah, where is the question?
jone,jake 14-Dec-14 2:11am    
cant count the total vowel to my input r

if you need to find total vowel count, don't use break inside the loop, it will exit after first character

C#
for (int x = 0; x < r.Length; x++)
{
    if (vow.Contains(r[x]))
    {
        count++;
    }
}
Console.Write("vowel count:{0}", count);
 
Share this answer
 
Comments
jone,jake 14-Dec-14 2:21am    
tnx bro...
what if the consonant i will count?
i just add a new,
char[] consonant = new consonant[]{ 'b', 'c', 'd', 'f', 'g' }//to z ???
DamithSL 14-Dec-14 2:56am    
now you know how to count the vowels, it may not be difficult to count the consonants if you try :)
If you use Linq, this gets very easy:
C#
// required
using Linq;

string r = Console.ReadLine();

int count = r.Count(ch => "aeiou".Contains(ch));

Console.WriteLine("vowel count:{0}", count);
 
Share this answer
 
Comments
jone,jake 14-Dec-14 3:02am    
like this :)
sample but useful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900