Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created September 25, 2018 00:02
Show Gist options
  • Save harrisonmalone/42aa34bc3a794e37e935eb4884c9a54a to your computer and use it in GitHub Desktop.
Save harrisonmalone/42aa34bc3a794e37e935eb4884c9a54a to your computer and use it in GitHub Desktop.
require 'pry'
def seconds_conversion(minutes, seconds)
minutes = minutes * 60
total = minutes + seconds
end
puts "------------------------
What would you like to do
------------------------"
puts "1 - Use time and distance to find pace"
puts "2 - Use time and pace to find distance"
puts "3 - Use pace and distance to find time"
user_input = gets.chomp.to_i
if user_input == 1
puts "Enter time in minutes"
minutes = gets.chomp.to_i
puts "Enter time in seconds"
seconds = gets.chomp.to_i
total_seconds = seconds_conversion(minutes, seconds)
puts "Enter distance in kms"
distance = gets.chomp.to_f
total = total_seconds / distance
minutes = total / 60
total_minutes = minutes.floor
seconds = minutes % 1
seconds = seconds * 60
seconds = seconds.round
puts "Your pace per kilometre is #{total_minutes} minutes #{seconds} seconds"
elsif user_input == 2
puts "Enter time in minutes"
minutes = gets.chomp.to_i
puts "Enter time in seconds"
seconds = gets.chomp.to_i
total_seconds = seconds_conversion(minutes, seconds)
puts "Enter pace in minutes"
pace_minutes = gets.chomp.to_i
puts "Enter pace in seconds"
pace_seconds = gets.chomp.to_i
total_pace_seconds = seconds_conversion(pace_minutes, pace_seconds)
total = total_seconds.to_f / total_pace_seconds
total = total.round(2)
puts "You ran a total of #{total} kilometres"
elsif user_input == 3
puts "Enter pace in minutes"
pace_minutes = gets.chomp.to_i
puts "Enter pace in seconds"
pace_seconds = gets.chomp.to_i
total_pace_seconds = seconds_conversion(pace_minutes, pace_seconds)
puts "Enter distance in kms"
distance = gets.chomp.to_f
total = total_pace_seconds * distance
minutes = total / 60
total_minutes = minutes.floor
seconds = minutes % 1
seconds = seconds * 60
seconds = seconds.round
puts "The total time of your run is #{total_minutes} minutes #{seconds} seconds"
else
puts "Error"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment