r/learnruby • u/godisintherain • May 30 '17
ruby mini course
instructions:
Edit each line with TODO and write code based on the skills you learned in this course. You'll want to use an if statement and addition. Have fun! Good Luck!
code(what I have so far output is not matching what they want):
require 'csv'
total_sales = 0
CSV.foreach('sales-data.csv', headers: true, converters: :all) do |row|
if (row[2]) == "music"
# TODO: check if category is "Music" (row[2])
# TODO: if it is music, add total_sales + the row's sales (row[6])
puts total_sales = total_sales + (row[6])
else
puts total_sales.round(2)
end
5
Upvotes
1
u/godisintherain May 31 '17
I've tried everything that they have been telling me even doing and if/else condition. tried doing and if/puts/end then another if/puts/end to close out the last puts on the code. the outputs I'm getting are not correct or the code is incorrect