Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
43 lines (38 sloc) 1.01 KB
/*
* =====================================================================================
*
* Filename: 05_04_kph_to_mph.c
*
* Description: Exercise 5.4
* Write a program that converts kilometers per hour to miles
* per hour.
*
* Version: 1.0
* Created: 09/17/2011
* Revision: none
* Compiler: gcc
*
* Author: Zach Williams, hey AT zachwill DOT com
*
* =====================================================================================
*/
#include <stdio.h>
int miles, kilometers;
float conversion = 0.6213712;
int convert_kph_to_mph(int kilometers) {
int mph;
float temp;
temp = (float) kilometers * conversion;
mph = (int) temp;
return mph;
}
int main(int argc, const char *argv[]) {
if (argc == 1) {
printf("You didn't enter a kph speed.\n");
return 1;
}
kilometers = atoi(argv[1]);
miles = convert_kph_to_mph(kilometers);
printf("%d mph\n", miles);
return 0;
}
Jump to Line
Something went wrong with that request. Please try again.