Skip to content
Open
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions PigLatin/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/PigLatin.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}
15 changes: 15 additions & 0 deletions PigLatin/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/PigLatin.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
90 changes: 81 additions & 9 deletions PigLatin/PigLatin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,88 @@ class Program
{
public static void Main()
{
// your code goes here
TranslateWords();
PlayAgain();

// leave this command at the end so your program does not close automatically
Console.ReadLine();
}

public static string TranslateWord(string word)
{
// your code goes here
return word;
void TranslateWords() {
Console.WriteLine("Please type in a word or sentence and press the Enter key.");
string sentence = Console.ReadLine().ToLower();
string[] words = sentence.Split(' ');
string[] translatedWords = new string[words.Length];
for (int j = 0; j < words.Length; j++)
{
char[] vowels = { 'a', 'e', 'i', 'o', 'u', 'y',};
string a = "a";
string e = "e";
string i = "i";
string o = "o";
string u = "u";
string y = "y";
string word = words[j];
int wordLength = word.Length;

if (word.Contains(a) || word.Contains(e) || word.Contains(i) || word.Contains(o) || word.Contains(u) || word.Contains(y))
{
int firstVowelIndex = word.IndexOfAny(vowels);
string firstHalf = word.Substring(0, firstVowelIndex);
int secondHalfLength = wordLength - firstVowelIndex;
string secondHalf = word.Substring(firstVowelIndex, secondHalfLength);
if (firstVowelIndex == 0)
{
string composite = secondHalf + firstHalf + "yay";
translatedWords[j] = composite;
}
else
{
string composite = secondHalf + firstHalf + "ay";
translatedWords[j] = composite;
}
}
else
{
translatedWords[j] = word + "yay";
}


// int firstVowelIndex = word.IndexOfAny(vowels);
// string firstHalf = word.Substring(0, firstVowelIndex);
// int secondHalfLength = wordLength - firstVowelIndex;
// string secondHalf = word.Substring(firstVowelIndex, secondHalfLength);
// if (firstVowelIndex == 0)
// {
// string composite = secondHalf + firstHalf + "yay";
// translatedWords[j] = composite;
// }
// else
// {
// string composite = secondHalf + firstHalf + "ay";
// translatedWords[j] = composite;
// }
}
string translatedSentence = String.Join(" ", translatedWords);
Console.WriteLine(translatedSentence);
}

void PlayAgain() {
string[] yes = { Convert.ToString('y'), Convert.ToString('Y'), "yes", "Yes", "YES"};
Console.WriteLine("Do you want to try again? [y/n]");
for (int i = 0; i < yes.Length; i++)
{
string choice = Console.ReadLine();
if (choice == yes[i])
{
TranslateWords();
PlayAgain();
}
else
{
Console.WriteLine("Bye!");
Environment.Exit(0);
}
}
}


}
}
}