Skip to content

Instantly share code, notes, and snippets.

@jamesmichiemo
Last active December 18, 2015 05:59
Show Gist options
  • Save jamesmichiemo/5736492 to your computer and use it in GitHub Desktop.
Save jamesmichiemo/5736492 to your computer and use it in GitHub Desktop.
expressions in Ruby language
# Pie Slice exercise
# Calculate how many slices each person will receive
#
print "How many slices are there per pizza? "
slices = gets.chomp.to_i
print "How many people are eating? "
people = gets.chomp.to_i
print "How many pizzas pies are there? "
pizza = gets.chomp.to_i
servings = (slices * pizza) / people;
puts "Each person will be able to eat #{servings} slices of pizza at the party."
# Leftover exercise
# Calculate the number of slices Spike gets to eat.
#
spikeLeftovers = (slices * pizza) % people
puts "If everyone at the party eats that same serving amount, Spike will get to eat #{spikeLeftovers} slices of the remaining pizza."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment