diff --git a/PigLatin/PigLatin.cs b/PigLatin/PigLatin.cs index 702647dd..6ceca99b 100644 --- a/PigLatin/PigLatin.cs +++ b/PigLatin/PigLatin.cs @@ -1,21 +1,62 @@ using System; +using System.Collections.Generic; namespace PigLatin { class Program { - public static void Main() + public static void Main(string[] args) { - // your code goes here - - // leave this command at the end so your program does not close automatically - Console.ReadLine(); + //stores user input into string sentence + Console.WriteLine("Enter a sentence to convert to PigLatin:"); + string sentence = Console.ReadLine(); + //takes translated sentence from ToPigLatin and then writes it into console + string pigLatin = ToPigLatin(sentence); + Console.WriteLine(pigLatin.ToLower()); } - - public static string TranslateWord(string word) + + //translates sentence + static string ToPigLatin (string sentence) { - // your code goes here - return word; + //creates list of words that the translated words are added to + List latin = new List(); + + //splits user entered input + foreach (string word in sentence.Split(' ')) + { + //checks position each vowel and y + int firstVowelIndex = word.IndexOfAny(new char[] {'A','E','I','O','U','a','e','i','o','u',}); + int firstYIndex = word.IndexOfAny(new char[] {'Y','y'}); + + //checks if Y acts as vowel + if ((firstYIndex > 0) && (firstYIndex < firstVowelIndex) && (word.ToLower().Contains("y"))) + { + string firstY = word.Substring(0, firstYIndex); + string restY = word.Substring(firstYIndex); + latin.Add(restY + firstY + "ay"); + } + //checks if word contains normal vowel + else if (firstVowelIndex > 0) + { + string first = word.Substring(0, firstVowelIndex); + string rest = word.Substring(firstVowelIndex); + latin.Add(rest + first + "ay"); + } + //checks if y acts as vowel in word with no other vowels + else if (firstYIndex > 0) + { + string firstY = word.Substring(0, firstYIndex); + string restY = word.Substring(firstYIndex); + latin.Add(restY + firstY + "ay"); + } + //checks if word starts with vowel or contains only consonents + else + { + latin.Add(word + "yay"); + } + } + //joins translated words together + return string.Join(" ", latin); } } -} +} \ No newline at end of file