Skip to main content

Section 19.5 Practice: Pointer Example

Check Your Understanding Check Your Understanding

1.

Challenge: Please write a function that converts a time given in minutes to hours and minutes. For example, 162 minutes should be converted to 2 hours and 42 minutes, whereas 59 minutes should be 0 hours and 59 minutes. The prototype and main function have been written already; all you have to do is write the function.

Compile and run the code below in your own C environment.

#include <stdio.h>

/* Here is your prototype. */
void minutesToHoursMinutes(int totalMinutes, int *hours, int *minutes);

int main(void) {
 
   int totalTime, newHours, newMinutes;
    totalTime = 0;

   printf("Enter total minutes to convert: ");
   scanf("%d", &totalTime);
   
    minutesToHoursMinutes(totalTime, &newHours, &newMinutes);
    printf("%d minutes equals %d hours and %d minutes.", totalTime, newHours, newMinutes);
    
    return(0);
}

/* Your function goes here. */
When your program performs correctly you’ll be given a keyword to enter in Canvas.