Topic: Making a simple Calculator using Ruby - for Beginners

This tutorial is found at … sing-ruby/

So here we are, all set to work on our first calculator using Ruby. Hope the previous simple tutorial on  Introduction to “puts”, your first Ruby Program has built good confidence to try and explore ruby further.

Open the ruby interpreter by clicking on start->Program->Ruby->interactive Ruby
and inside the ruby command window type
  5 + 10

Ruby does the entire math like a scientist on fire and then throws in the result and says, boss 10+5  is “15″.

Isn’t that awesome?  a simple program so easy to read and execute.

Now let’s see if ruby is able to do more math.
Inside the ruby command window type in
irb(main):001:0> 10+2-10+5*6
=> 32

At this point of tutorial  I just typed in random numbers and Surprisingly ruby answered it as  “32″

Try throwing weird calculations at ruby and have fun, punch in random numbers divide it by a number, multiply it, add it etc.

Ruby can do complex math as well
irb(main):003:0> 62 + (24951 / (13*68)) * -100
=> -2738

Ruby can find a Square root

and the answer is
irb(main):007:0> Math.sqrt(4)
<pre>=> 2.0

wasn’t all that easy? And we thought only a programmer  can write a complex calculation. These are all simple calculations. Ruby can do much more with complex calculations. But we will skip all those complex things as I don’t want you to get confused and after all maths in not everyone’s favorite.
NUMBERS in programming are called INTEGERS

Whenever you hear someone telling you the the word “INTEGER” don’t get shocked by the word.  They are only talking about numbers. We will work with integers while we take a walk further into the jungle.

Congratulation, you are slowly making into the programming world. I am taking all these chapters pretty slow, so that a beginner can have no problem in understanding the basics. I promise we will advance further once you get the basics right.
Although Ruby can calculate math much more than we can even imagine. The reason for this tutorial here was to tell you that math is not a boring subject anymore when you work with Ruby.
What did you learn?

   1. You learn t its easy to use math in ruby
   2. You learn t Ruby calculates math as fast as a scientist on fire
   3. You learn t that the word INTEGER is nothing but MATH in a layman’s world
   4. You learn t that math is no longer a boring subject when it comes to ruby