jeudi 6 juillet 2017

Program Flow C#

I am learning C# at the moment. In the example below, I believe I have the correct code but there must be an error or two (maybe more) somewhere. Please see the code below:

    public static string ReturnAgeGroup(int age)
    {
        if (age >= 65)
        {
            return "senior citizen";
        }
        if (age < 21)
        {
            return "minor";
        }
        if (age >= 21 & age < 65)
        {
            return "adult";
        }
    }

There is a red squiggly line underneath RetrunAgeGroup, which says not all code paths return a value when I hover over it. Why is this? Every possibility, regarding age, is covered by the conditions.

Is/are there any other error(s) that I have failed to identify?

Regards

Aucun commentaire:

Enregistrer un commentaire