#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

puts "勉強時間を計測します"
puts "enterキーでスタート"
saisyo = gets.chomp
puts"計測中...\nenterキーで終了"
kaisi = Time.now.to_i                       
teisi = gets.chomp
syuryo = Time.now.to_i                     
taimu = syuryo - kaisi                      
hun = taimu / 60                            
byou = taimu - hun * 60                    
zikan = hun / 60
puts "勉強時間は"
while zikan > 0
  printf("%d時間", zikan)
  break
end

while hun > 0
  printf("%d分", hun)
  break
end

printf("%d秒", byou)
puts"でした"

puts"結果を入力してください"

puts"今日は?"
puts"何月?"
tuki = gets.to_i
puts"何日?"
hiniti = gets.to_i 
puts"勉強時間は?"
puts"何時間?"
ji = gets.to_i 
puts"何分?"
hun = gets.to_i
kekka = "#{tuki}月#{hiniti}日は#{ji}時間#{hun}分"
kekka1 = "\n#{kekka}"
puts"記録を記録します"
file = File.open("benkyoukekka.txt","a")

file.write(kekka1)
file.close

file = File.open("benkyoukekka.txt","r")

puts(file.read)
file.close
