85.3k views
4 votes
Silas develops this algorithm to compute the calories burned for an activity for a given number of minutes and body weight: If the activity is running, compute caloriesPerMin by dividing weight by 10.5 If the activity is walking, compute caloriesPerMin by dividing weight by 15.5 Compute numCalories by multiplying caloriesPerMin by numMinutes He implements the algorithm in an app, and users soon ask for the ability to compute the total calories for multiple sessions of walking or running. What structure must be added to the original algorithm so that it can compute the total across multiple sessions

User Markm
by
7.5k points

1 Answer

7 votes

Answer:

Step-by-step explanation:

This change can be accomplished in one of two ways. The first being creating a global variable that adds to it and saves the total calories burned at the end of every session. This global variable can then be called at any time to show the total number of calories burned in all previous sessions combined. The other option would be to create a list of Session objects. Each object would hold all the information regarding each session including calories burned. Then create a function that loops through this list, adding the total calories burned in each session and outputting the total.

User Yuxh
by
7.6k points