using System;
public class Getstngvowels
{
public static void Main()
{
while (true)
{
Console.Write("Enter a vowel or ! to exit: ");
string input = Console.ReadLine();
if (input == "!")
{
break;
}
else if (IsVowel(input))
{
// a vowel was entered
Console.WriteLine("OK");
break;
}
else
{
Console.WriteLine("Do you know what a vowel is?! you crap load! Try again.");
}
}
}
private static bool IsVowel(string s)
{
if (s.Length != 1)
return false;
s = s.ToLowerInvariant();
if (s == "a" || (s == "e") || (s == "i") || (s == "o") || (s == "u"))
{
return true;
}
else
{
return false;
}
}
}
Explain looping
Started by digitalbeef, Nov 01 2009 08:37 PM
1 reply to this topic
#1
Posted 01 November 2009 - 08:37 PM
A user posted this a little while ago, and I have never used private class before. Can somebody explain how exactly this program works for me? Mainly just the code in private and how it directly relates to the remainder of the program. Thx
|
|
|
#2
Posted 01 November 2009 - 09:28 PM
It's not a private class, the public class has a private function, basically the user using the class cannot access the function only the class itself can.
It looks like if a vowel is entered it breaks the loop, if not it asks again.
It looks like if a vowel is entered it breaks the loop, if not it asks again.


Sign In
Create Account


Back to top










