#!/usr/koeki/bin/ruby # -*- coding: utf-8 -*- sum = 0 for subject in ["英語", "数学", "国語"] print subject + "は何点? " sum += gets.chomp.to_i end open("output.txt", "w") do |f| f.printf("合計は%d点です\n", sum) end