Completed the output calculation code. Only one function left to implement.