Debug Help: Arrays & Structs

I’m doing the Arrays & Structs exercise but everything but FindAverageAgeWorks:

pragma solidity ^0.4.0;

contract PeopleContract{
uint a = 0;
uint p = 0;
uint e = 0;

    
struct Person{
    string name;
    uint age;
    
}    
    
    
    
    Person[] people;

    
function addPerson(string _name, uint _age){
        people.push(Person(_name, _age));
        p = p + 1;
        a = a + _age;
    }
 
function getPerson(uint _id) returns (string){
     return people[_id].name;
    }

function findAverageAge() returns (uint){
    e = a/p;
    
    return e;
    } 

}

I have already tried a few things like instead of using arrayName.length I used a variable to keep track and getting rid of the for loop but turns out that wasn’t the problem. Anyone know what is?

Did you populate the people array first before calling the findAverageAge() function? Otherwise you’ll get an error because you can’t divide by zero.