Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 51 additions & 10 deletions PigLatin/PigLatin.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,62 @@
using System;
using System.Collections.Generic;

namespace PigLatin
{
class Program
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see the tests.

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<string> latin = new List<string>();

//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")))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if firstYIndex is greater than 0 then the word must contain a 'y' so that last condition is not really needed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if firstYIndex is greater than 0 then the word must contain a 'y' so that last condition is not really needed.

{
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);
}
}
}
}