Write a program to calculate the estimated journey time of a train. The
program should request and read the distance in miles and the average
speed in miles per hour, and display the estimated journey time in hours
and minutes to the nearest minute.
Test your program with:
a) Distance = 1.01, speed = 1. [Result should be 1 hour & 1 minute.]
b) Distance = 1.005, speed = 1. [Result should be 1 hour & 0 minutes.]

here are my codes:

#include <stdio.h>
#include <stdlib.h>
int main()
    float dist, speed;
    float time;

    printf("Enter Distance in miles: ");
    scanf("%f", &dist);
    printf("Enter Speed in miles per hour: ");
    scanf("%f", &speed);


    printf("The estimated journey is %.2f", time);


as in the question is said to display the time in hours and minutes! my problem here is i do not know how to do it any help? i think that the final should be "1 hour & 1 minute" display on the window

Edited by JorgeM: moved to the C forum category

3 Years
Discussion Span
Last Post by ddanbe

If time = 12.5 for example then the integral part is the number of hours, So here this would be12 hours. Multiply the fractional part by 60 to get the minutes. Here this would be 0.5 x 60 = 30 minutes. Hope this helps.

Edited by ddanbe: typo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.