Answer to Question #298805 in C# for Zyke

Question #298805

Write a source-code that counts the number of vowel, consonant letters and the total number of letters on


a text. Use this text: “This is the sample text!”.

1
Expert's answer
2022-02-18T07:31:40-0500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<char> vovels = new List<char>() { 'a', 'e', 'i', 'o', 'u', 'y' };
            List<char> consonants = new List<char>() { 'b', 'c', 'd', 'f', 'g', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 's', 't', 'v', 'x', 'z', 'h', 'r', 'w' };
            string text = "This is the sample text!";
            int vovelCount = 0;
            int consonantCount = 0;
            int totalLetters = 0;

            for (int i = 0; i < text.Length; i++)
            {
                if (char.IsLetter(text[i]))
                {
                    totalLetters++;
                }
                if (vovels.IndexOf( text.ToLower()[i]) > -1)
                {
                    vovelCount++;
                }
                if (consonants.IndexOf(text.ToLower()[i]) > -1)
                {
                    consonantCount++;
                }
            }

            Console.WriteLine("Vovel count: {0}", vovelCount);
            Console.WriteLine("Consonant count: {0}", consonantCount);
            Console.WriteLine("Total letters: {0}", totalLetters);


            Console.ReadKey();
        }
    }

   
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS