I'm new to C# and I'm having trouble with the OR operator. I've watched several tutorials and haven't figured out what's wrong yet.
Essentially, if the age is 8 or between 80 or 89, it's grammatically correct to say "an 8 year old" or "an 85 year old". Otherwise the article would be "a" as in "a 3 year old" or "a 10 year old". The whole purpose of this method is to compensate for that. However, the MessageBox will always show "Patient is AN 49 year old" regardless of the actual age found in int age. The condition is obviously not working here.
Can someone point me in the right direction?
THank you!
C#:
public static string AgeArticleModifier(int age, string ageUnit) {
string strAgeArticle;
if (age == 8 || age == 18 || age >= 80 || age <= 89)
{
strAgeArticle = "an";
MessageBox.Show("Patient is " + strAgeArticle + " " + age + " " + " year old");
return strAgeArticle;
}
else
{
strAgeArticle = "a";
MessageBox.Show("Patient is " + strAgeArticle + " " + age + " " + " year old");
return strAgeArticle;
}
}
Essentially, if the age is 8 or between 80 or 89, it's grammatically correct to say "an 8 year old" or "an 85 year old". Otherwise the article would be "a" as in "a 3 year old" or "a 10 year old". The whole purpose of this method is to compensate for that. However, the MessageBox will always show "Patient is AN 49 year old" regardless of the actual age found in int age. The condition is obviously not working here.
Can someone point me in the right direction?
THank you!