Day 2.0 Exercise 3 Numbers and Math

Here’s my work on GitHub.
Here’s the link to exercise 3.

Ex03 Code
Exercise 3 Codes
Ex03 Shell
The output of exercise 3 on the terminal
Ex03 irb
Exercise 2 IRB. Made a mistake on 007, > = should be >=

Study Drills

1. Above each line. use the # to write a comment to yourself explaining what the line does.
Did that, but not all the lines, puts command are common sense now, right??? I did do the math with their brackets on, so I could tell what’s going on.

2. Remember in Exercise 0 when you started irb? Start irb this way again and using the math operators, use Ruby as calculator.
This starts off a little weird to me. Interactive Ruby Shell (irb). The author hasn’t explain much about how to use it, other than letting us know it is there. However, As you see above, that is the irb, how it should look like and what kind of error you’d get if you made a typo like me. To quit, simply type quit, which I forgot to include in the pic.

3. Find something you need to calculator and write a new .rb file that does it.
Unfortunately, I couldn’t find anything near me that I need to calculate at the time working on this.

4. Notice the math seems “wrong”? There are no fractions, only whole numbers. You need to use a “floating point” number, which is a number with decimal point, as in 10.5, or 0.89, or even 3.0.
Yes, that is due to data types as commented in the 1st picture. In older languages such as C++, it is required to declare what type of data being use. However in ruby, ruby does it for you as soon as you write it in decimal, so 1 would be int data type (integer), and 2.0 would be a float data type.

5. Rewrite ex3.rb to use floating point numbers so it’s more accurate. 20.0 is a floating point.
Look at the above comments for instructions on how to convert int to floating points.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s