rubilicious

Learn Ruby the Hard Way

by Zed Shaw

Example 4

Previous   Next

# defining the variable cars with the integer 100
cars = 100

# defining the variable space_in_car with the floating point 4.0
space_in_car = 4.0

# defining the variable drivers with the integer 30
drivers = 30

# defining the variable passengers with the integer 90
passengers = 90

# defining the variable passengers with the integer 90
cars_not_driven = cars - drivers

# defining the variable cars_driven with the output of the variable drivers
cars_driven = drivers

# defining the variable carpool_capacity with the equation cars_driven multiplied by space_in_car
carpool_capacity = cars_driven * space_in_car

# defining the variable average_passengers with the equation passengers divided by cars driven
average_passengers_per_car = passengers / cars_driven

# uses the method puts to print and return to the next line; the string including the variable cars.
puts "There are #{cars} cars available."

# uses the method puts to print and return to the next line; the string including the variable drivers.
puts "There are only #{drivers} drivers available."

# uses the method puts to print and return to the next line; the string including the variable cars_not_driven.
puts "There will be #{cars_not_driven} empty cars today."

# uses the method puts to print and return to the next line; the string including the variable car# uses the method puts to print and return to the next line the string including the variable carpool_capacity.
puts "We can transport #{carpool_capacity} people today."

# uses the method puts to print and return to the next line; the string including the variable passengers.
puts "We have #{passengers} passengers to carpool today."

# uses the method puts to print and return to the next line; the string including the variable average_passengers_per_car.
puts "We need to put about #{average_passengers_per_car} in each car."