I have to write this program where when the user enters a word, it changes it to the plural version of it. I have three rules.
- if it ends in a ‘y’, we change it to ‘ies’
- if it ends in “sh” or “ch”, we add “es” to the end
- Else, We add a ‘s’ at the end
I have this function named WhichRule( char word[], char plural [])
, I am supposed to write if statements so I can see which rule to apply, the function WhichRule
will call RuleOne( char word[], char plural [])
, RuleTwo( char word[], char plural [])
, and RuleThree( char word[], char plural [])
.
I am having trouble writing my if statements, the code im going to copy is two different ways in which I’ve tried to write my if statements, but none have worked. I would appreciate any help.
void WhichRule(char word[], char plural[])
{
int len = strlen(word);
if (word[len - 1] = 'y')
{
ApplyRuleOne(plural, word);
printf("this");
}
else if (word[len - 2, len - 1] = 'c', 'h')
{
ApplyRuleTwo(plural, word);
printf("is");
}
else if (word[len - 2] == 's' && word[len - 1] == 'h')
{
ApplyRuleTwo(plural, word);
printf("a");
}
else
{
ApplyRuleThree(plural, word);
printf("test");
}
}