lukestsk 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

program1 by lukestsk

#Name: Lucas Kuenneke
#Course: BIO371
#Data 5/4/2011
#Programming Assignment #1

number = 0, toadd = 0, total = 0

#Get user input for total number of inputs, convert to int for looping.
toadd = ask "How many numbers would you like to average?\n"
toadd = toadd.to_i

#Get number, add to total until all numbers have been input.
toadd.times do
number = ask "Please enter the next number.\n"
total = number.to_f + total.to_f
end

#calculate average, assign to total.
total = total.to_f / toadd.to_f

#output the total numbers and average.
alert "The average of the " + toadd.to_s + " numbers you entered is " + total.to_s