C#: Prompt the user to input a sentence. Once you have their sentence, figure out how many vowels (a, e, i, o, u) and how many consonants are in the sentence. Output the total number of consonants and vowels in the following format (2 separate lines and the format specifier should be general with 0 decimal places!)
There were 5 vowels in the sentence.
There were 15 consonants in the sentence.
using System; class MainClass { public static void Main (string[] args) { Console.WriteLine("Enter your sentence: "); string sentence = Console.ReadLine().ToLower(); int vowelCount = 0; int consonantsCount = 0; for (int i = 0; i < sentence.Length; i++) { char c = sentence[i]; if (char.IsLetter(c) && (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')) { vowelCount++; } else if (char.IsLetter(c)) { consonantsCount++; } } Console.WriteLine ("There were " + vowelCount + " vowels in the sentence."); Console.WriteLine ("There were " + consonantsCount + " consonants in the sentence."); } }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.
Get Answers For Free
Most questions answered within 1 hours.