Last active
December 18, 2015 05:59
-
-
Save jamesmichiemo/5736492 to your computer and use it in GitHub Desktop.
expressions in Ruby language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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