From: Shadowfirebird Date: 2010-11-11T19:07:18+09:00 Subject: Re: Emacs/putty code help [linux] > code: > puts "This program was created by Thierry NY > puts "Project 5, November 10th 2010." > puts "Program description: This is a statistical program to calculate > floating-\ > point numbers and output their mean and median. > > nums = [] > if ARGV[0] == nil > print "no argument detected, please enter filename." > filename = gets.to_s.chomp > else > filename = ARGV[0] > end > > f = open filename, "r" > while x = f.gets > nums << x.to_f > end > f.close > nums = nums.sort > > count = nums.size -1 > mean = 0 > until count == -1 > mean = mean + nums[count] > count = count -1 > end > mean = mean/nums.size.to_f > > if nums.size%2! = 0 > midindex = (nums.size-1)/2 > median = nums [midindex] > else > midindex1 = (nums.size-1)/2 > midindex2 = (nums.size)/2 > median = (nums[midindex1] + nums[midindex2])/ > end > > puts "The mean is: # {mean}" > puts "The median is: # {median}" Okay, this looks like homework, but since you're not actually asking us to do it for you, I'll bite (byte?) I'm seeing a bunch of syntax errors. You need to look at the error messages ruby is giving you and try and work out what you spelled wrong / missed out. Often the actual problem will be on the line above the one Ruby thinks the problem is on. I'll give you the first one for free: on the second put statement, the extended line ending "median" should have a close quote. If you get stuck again, post the error messsage and I'll try to help. (Or maybe someone else will ... it's a big list.) -- It's not an optical illusion, it just looks like one. -- Phil White