Kinetic Energy in F# November, 2007
I have been wanting to dig into F# for quite some time and finally got an opportunity. My first stab at it implements the calculation of kinetic energy given a weight in lbs, speed in mph and output in kJ. Pretty basic, but ya gotta start some where right? :)
// Get info from the user
do Printf.printf "Enter the weight (LBS): "
let m = read_line()
do Printf.printf "Enter the velocity (MPH): "
let mph = read_line()
// Pound to kilogram conversion
let kg lbs = lbs / 2.2
// Miles/h to Meters/s conversion
let mps mph = (((mph * 1.6) * 1000.0) / 60.0) /60.0
// Kinetic energy calculation
let Ek m v = (0.5 * m * (v * v)) / 1000.0
// Show me the money
do Printf.printf "\nEk = %fkJ\n\n" (Ek (kg (float_of_string m)) (mps (float_of_string mph)))
// Wait! Let me see the answer...
do Printf.printf "Press enter to continue..."
let x = read_line()