Here's the question you clicked on:
JadeEyes
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 ninute. 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 minute)
The codes I entered: #include<iostream.h> #include<stdio.h> int main () { float distance,speed,time; int hour,minute; printf("Enter Distance Of Journey(in miles):\n"); scanf("%f",&distance); printf("Enter Average Speed Of Train(in miles per hour):\n"); scanf("%f",&speed); time = distance/speed; hour = distance/speed; minute = 60*(time-hour); <----- Problem here : For any value minutes=zero printf("Approximate Journey Time: %d hour and %d minutes.\n",hour,minute); system("pause"); return 0; } Can anyone help me resolve this problem? I'm using Dev C++.
#include<stdio.h> int main () { float distance,speed,time,minute; int hour,min; printf("Enter Distance Of Journey(in miles):\n"); scanf("%f",&distance); printf("Enter Average Speed Of Train(in miles per hour):\n"); scanf("%f",&speed); time = distance/speed; minute = 60*time; if(minute>=60) { hour=minute%60; min=minute/60; } printf("Approximate Journey Time: %d hour and %d minutes.\n", hour,min); system("pause"); return 0; }
Thank you again...!! :) ..!!