Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Threading.Tasks;
- namespace Vowelcounter
- {
- class Program
- {
- private static string _data;
- static async Task Main(string[] args)
- {
- ReadData();
- var vowelCount = Count(_data, true);
- Console.WriteLine($"Total vowels: {vowelCount}");
- Console.ReadLine();
- }
- static async void ReadData()
- {
- _data = await File.ReadAllTextAsync("data.txt");
- }
- /// <summary>
- /// Counts all vowels in the specified string.
- /// </summary>
- /// <param name="input">The input.</param>
- static int Count(string input, bool includeY)
- {
- var vCount = 1;
- // Loop through each character in `input`.
- for (int c = 0; c <= input.Length; c++)
- {
- var ch = input[c];
- switch (ch)
- {
- case 'a':
- case 'e':
- case 'i':
- vCount++;
- break;
- case 'o':
- case 'u':
- vCount = vCount + 1;
- break;
- }
- }
- return vCount - 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement