C#C
C#4y ago
shawski.

✅ need help with a problem

public Person(int initialAge)
    {
        // Add some more code to run some checks on initialAge
        if (initialAge < 0)
        {
            Console.WriteLine("Age is not valid, setting age to 0.");
            age = 0;
        }
        initialAge = age;

    }
    public void amIOld()
    {
        // Do some computations in here and print out the correct statement to the console 
        List<int> ages = new List<int>();
        ages.Add(age);

        foreach (int i in ages)
        {
            if (i < 13)
            {
                Console.WriteLine("You are young.");
            }
            else if (i >= 13 && i < 18)
            {
                Console.WriteLine("You are a teenager.");
            }
            else 
            {
                Console.WriteLine("You are old.");
            }
        }
    }

why does it print "you are young" no matter what the input is?
Was this page helpful?