+ 1

Need help with vowel counter in C#

namespace Sololearn { class Program { static void Main(string[] args) { int count = 0; string words = Console.ReadLine(); char[] vowels = {'a','e','i','o','u','A','E','I','O','U'}; foreach (char i in vowels) if (words.Contains(i)) { count++; Console.WriteLine(i); } Console.WriteLine(count); } } } Ive almost got it figured out. I know my issue is that it's not counting vowels more than once. I just can't figure out how to make it work right. Thanks in advance!

22nd Dec 2021, 3:34 AM
Harley Wilkinson
Harley Wilkinson - avatar
2 Answers
+ 3
Instead of checking whether letters in vowels are in words check whether letters in words are in vowels.
22nd Dec 2021, 3:41 AM
Simon Sauter
Simon Sauter - avatar
+ 2
Thanks that totally worked.
22nd Dec 2021, 4:38 AM
Harley Wilkinson
Harley Wilkinson - avatar