117k views
2 votes
Write code in MinutesToHours that assigns totalHours with totalMins divided by 60

Given the following code:

Function MinutesToHours(float totalMins) returns float totalHours
totalHours = MinutesToHours(totalMins / 60)
// Calculate totalHours:
totalHours = 0

Function Main() returns nothing
float userMins
float totalHours

userMins = Get next input
totalHours = MinutesToHours(userMins)

Put userMins to output
Put " minutes are " to output
Put totalHours to output
Put " hours." to output

2 Answers

4 votes

Final answer:

The code for the MinutesToHours function should directly calculate the number of hours by dividing the given totalMins parameter by 60.

Step-by-step explanation:

The MinutesToHours function needs to calculate the number of hours based on the input minutes. The code snippet provided does not correctly implement the intended operation. To fix it, the computation should occur within the function itself, dividing totalMins by 60 to get the equivalent hours. The correct code for the function would look like this:

Function MinutesToHours(float totalMins) returns float
{
float totalHours;
totalHours = totalMins / 60;
return totalHours;
}

The Main function will then call this corrected function to convert user input from minutes to hours.

User Alex Stoicuta
by
7.7k points
3 votes

Answer:

Function MinutesToHours(float totalMins) returns float totalHours

// Calculate totalHours:

totalHours = totalMins / 60

return totalHours

End Function

User Paul Ramsey
by
7.4k points