I have a project in my programming class. This is my assignment: Create a program that allows the user to input how many hours they exercised for today. Then the program should output the total of how many hours they have exercised for all time. To allow the program to persist beyond the first run the total exercise time will need to be written and retrieved from a file.
This is the code I have so far:
File.open("exercise.txt", "r") do |fi|
file_content = fi.read
puts "This is an exercise log. It keeps track of the number hours of exercise. Please enter the number of hours you exercised."
hours = gets.chomp.to_f
end
output = File.open( "exercise.txt", "w" )
output << hours
output.close
end
What else do I have to add in it?
get_total_to_dateandsave_total_to_date(total)? Since the file name will not change and you reference it more than once, best to make it a constant. Note that the file will not exist the first time you invokeget_total_to_date.