I am working on a Ruby project to make a road trip calculator. The program takes the miles per gallon and fuel tank size from multiple users to calculate and compare fuel economy. In the following portion of code I want to iterate over an array named vehicles and divide 3000 by the mpg of each element in that array.
I'm struggling with what I want to do next: take those outputs and sum them (3000 / total_fuel[:mpg] + 3000 / total_fuel[:mpg] + 3000 / total_fuel[:mpg] ... of each element). So far this is what I have:
vehicles.each do |total_fuel|
total_fuel = (3000 / total_fuel[:mpg])
print total_fuel
end
When it prints it just outputs the calculations right next to each other with no spaces (eg 150166). I'm totally lost on how to then take those numbers and add them, especially since it will be a different amount of outputs depending on how many users entered info.
I hope that was clear. Any ideas?
` The line of code you provided worked though! – KarGuad Oct 25 '18 at 09:53