How to calculate a total value based on user input?