Counting vowels in a string with C Sharp

using System;

public class CountVowels{
	public static void Main(string[]args){
		Console.Write("Enter a phrase: ");
		string line = Console.ReadLine();
		if(null == line){
			Console.WriteLine("\nError: Missing input phrase!");
			return;
		}
		int vowels = 0;
		foreach(char c in line){
			switch(c){
				case 'a':
				case 'e':
				case 'i':
				case 'o':
				case 'u':
				case 'A':
				case 'E':
				case 'I':
				case 'O':
				case 'U':
					vowels ++;
					break;
			}
		}
		Console.WriteLine("{0} vowels found in phrase: \"{1}\"", vowels, line);
	}
}
Download

Comments

Popular posts from this blog