Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice Ruby Numeric Types!
You have completed Practice Ruby Numeric Types!
Preview
Now that you've coded your solution to the practice problem, I'll show you how I did it.
One Solution
Here's my code:
a = 12
b = 7
c = 5
d = 10
puts (a + b + c + d) / 4.0
Additional Experimentation
Try writing programs that calculate the perimeter or area of a rectangle or triangle.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
It's okay if yours is slightly different,
but if you see something interesting in my
0:00
code, you should consider borrowing
it to improve your own program.
0:00
Okay, so to calculate an average, we need
to add the four values in the A, B, C and
0:04
D variables together, and then divide
by 4 that's the total number of values.
0:09
Then we need to print the result out.
0:13
So to print it,
we're gonna need to call the puts method.
0:15
Now the first thing you might have tried
was to simply add a + b + c + d together.
0:18
And then divide the result by 4.
0:26
Unfortunately, that won't work because
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up