Completed code to calculate values