Chapter 7: Add recursive function to perform calculation