simple Ruby Input and Output Exercise log
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 to do I have to add?
No comments:
Post a Comment