Question
Date: Thu, Feb 25, 2021 5:14 pm Good Evening, I am in need of your assistance. I am experiencing difficulty in solving this C shape
Date: | Thu, Feb 25, 2021 5:14 pm |
Good Evening,
I am in need of your assistance. I am experiencing difficulty in solving this C shape programming problem. I am in need of your help. Please see below. Thank you
For the input I got "i t", I should get the
output in pig latin " iway tay" but I get nothing. That goes the same for typing the word "string" to get ingstray. Do you know how I would fix this?
Heres my code:
static void Main(string[] args)
Console.WriteLine("Line:");
//get user line
string line = Console.ReadLine();
// split line into words
string[] words = line.Split(' ');
// iterate over words in the array
for (int i = 0; i < words.Length; i++)
{
// check if the word in the words array starts with vowel
if (isVowel(words[i]) == true)
{
words[i] = words[i] + "way";
}
else
{
string output;
string temp = words[i];
do
{
// parse the string using temp variables
output = temp.Substring(1) + temp[0];
if (isVowel(output) == true)
{
//add ay to the string
words[i] = output + "ay";
}
else
{
// parse the string
output = output.Substring(1) + output[0];
//add ay to the string
words[i] = output + "ay";
}
} while (isVowel(output) == false);\ }
}
// print the words
for (int i = 0; i < words.Length; i++)
{
Console.WriteLine(words[i]);
} Console.ReadLine();
// method to validate the word whether it is starts with vowel or not
static bool isVowel(string word)
{
if (word[0] == 'a' || word[0] == 'e' || word[0] == 'i' || word[0] == 'o' || word[0] == 'u')
{ return true;
} else
{ return false;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started