Skip to content

Instantly share code, notes, and snippets.

@jjb
Created January 25, 2015 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjb/fcda61801b54cc3f13d1 to your computer and use it in GitHub Desktop.
Save jjb/fcda61801b54cc3f13d1 to your computer and use it in GitHub Desktop.
print "Fat: "
fat = gets.strip
print "Protein: "
protein = gets.strip
print "Carbohydrates: "
carbs = gets.strip
fat_calories = fat.to_f*9
carb_calories = carbs.to_f*4
protein_calories = protein.to_f*4
total_calories = fat_calories + carb_calories + protein_calories
fat_portion = ((fat_calories/total_calories) * 100).truncate
protein_portion = ((protein_calories/total_calories) * 100).truncate
carb_portion = ((carb_calories/total_calories) * 100).truncate
output = ""
output << "Total Calories: #{total_calories}"
output << "\n\n"
output << "Fat/Protein/Carb ratio: #{fat_portion}%/#{protein_portion}%/#{carb_portion}%"
puts output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment