6.9.(Write a program using string functions)
Write a program that takes nouns and forms their plurals on the basis of these rules:
a. If a noun ends in “y”, remove the”y” and add “ies”
b. If a noun ends in "s”, “ch” or “sh”, add "es”
c. In all other cases, just add “s”
internal class Program
{
static void Main(string[] args)
{
Console.Write("Enter your word:");
string word = Console.ReadLine();
Console.WriteLine($"Your word is plural: {PluralForm(word)}");
Console.ReadKey();
}
public static string PluralForm(string word)
{
string[] ends = { "s", "ch", "y", "sh" };
foreach (string letters in ends)
{
if (word.EndsWith(letters) & letters == "y")
{
word = word.Remove(word.Length - 1, 1);
return word += "ies";
}
else if (word.EndsWith(letters))
{
return word += "es";
}
}
return word += "s";
}
}
Comments
Leave a comment