sexton
and many others are using
Hackety Hack
to learn how to code.
Hackety Hack is a free program for Windows, Mac OS X and Linux that can teach you how to make games, applications and more and share those programs with your friends. You can ask other budding programmers questions and follow them to see what code they're working on through the Hackety Hack website.
Sign up
Learn More
#Dereck Sexton
#CS271/BIO371
#programming assignment 1
#Dr. Krane and Dr. Raymer
#program that takes in a set number(user specified) values
# and calculates the average of the sum total of values
#There is a lot of extra code in this program to help me
# get a feel for the language
number = ask " How many numbers would you like to average?"
number = number.to_i
avg = 0.0
arrAvg = 0.0
item = 0.0
numArr = Array.new
#first way of adding items together
#stores values in an array
number.times do
item = ask "Enter a value."
item = item.to_i
numArr << item
avg = avg + item
end
#second way of averaging items
#computes the total sum from the array
number.times do
arrAvg = numArr.shift + arrAvg
end
#calculates the averages of both methods
arrAvg = arrAvg / number
avg = avg / number
#compares the averages of both methods
if avg == arrAvg
alert "The average of the " + number.to_s + " numbers you entered is " + avg.to_s + "."
else
alert "precision error"
end