float seconds, fps, mps, total;
There is rarely a reason to use float over double, especially when doing calculations involving floating point numbers. I'd recommend you change the type to double.
Also, as floating point numbers aren't represented exactly, it's always good to use integral types (int, unsigned, short, etc...) for each time denomination; a variable for hours, a variable for minutes, a variable for seconds, etc.
1 2
|
fps = 5280 / total;
mps = fps * 0.3048;
|
You're assuming that the runner runs a distance of a mile. You haven't asked the user for the distance. Also, what do the magic numbers 5280 and 0.3048 mean? Whenever you have these magic numbers, it's a good practice to name them and make them constants, to improve readability of code. For example,
|
const double fps_to_mps = 0.3048;
|
As for turning your conversions to functions
1 2 3 4
|
double calculate_fps( double mi, int sec )
{
// code here
}
|