/*
CTIS 151 Introduction to Programming
Purpose: Given a distance in meters and the speed of a car in miles per
hour (mph), calculate how many minutes it will take for that car to
travel that distance.
Written by Berrin Kafkas Feb. 8, 2008
*/
#include <stdio.h>
#define METERS_PER_MILE 1609.344
int main (void)
{
double meters, // input - distance in meters
miles, // distance in miles
speed, // input - speed in mph
hours, // time in hours
minutes; // output - time in minutes
// Get the distance in meters
printf ("Enter the distance in meters: ");
scanf ("%lf", &meters);
// Get the speed of the car in miles per hour
printf ("Enter the speed of the car in mph: ");
scanf ("%lf", &speed);
// Calculate the time in minutes
// Convert the distance in meters to miles
miles = meters / METERS_PER_MILE;
hours = miles / speed; // Calculate the time in hours
minutes = hours * 60; // Convert the time in hours to minutes
// Display the time in minutes
printf ("The car will travel %0.2f meters in %0.1f minutes.\n",
meters, minutes);
return (0);
}
#include <stdio.h>
int main (void)
{double x, y, s, h, m;
printf ("Enter the distance in meters: "); scanf ("%lf", &x);
printf ("Enter the speed of the car in mph: "); scanf ("%lf", &s);
y = x / 1609.344; h = y / s; m = h * 60;
printf ("The car will travel %0.2f meters in %0.1f minutes.\n", x, m);
return (0);}