Skip to content

Instantly share code, notes, and snippets.

@matthewd673
Last active August 29, 2015 14:15
Show Gist options
  • Save matthewd673/0e2ab5fbe17fb0e7168d to your computer and use it in GitHub Desktop.
Save matthewd673/0e2ab5fbe17fb0e7168d to your computer and use it in GitHub Desktop.
Farhanalee asked for help on DaniWeb. Here you go, Farhanalee
//Assumed this was a console app
readAString()
{
Console.WriteLine("Type in a word and BE AMAZED!");
string input = Console.ReadLine;
Console.WriteLine(Convert.ToString(countVowels(input)) + " vowels. Now you know!");
Console.ReadKey();
//Not sure how isVowel fits in here but you get the idea
}
//Real simple addition here
int countVowels(String word)
{
int ct = (word.Split('a').Length - 1) + (word.Split('e').Length - 1) + (word.Split('i').Length - 1) + (word.Split('o').Length - 1) + (word.Split('u').Length - 1);
return ct;
}
//To check if the character is a vowel
//Could also be accomplished with big long 'if' statement
//Just couldn't decide which was better, so I went with a 'switch'
bool isVowel(char ch)
{
switch(ch)
{
case 'a':
return true;
break;
case 'e':
return true;
break;
case 'i':
return true;
break;
case 'o':
return true;
break;
case 'u':
return true;
break;
case 'y':
return true;
break;
default:
return false;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment