Scout to Scout: Programming Requirement 5b

Scout to Scout: Programming Requirement 5b

December 26, 2017 Merit Badge Programming Scout to Scout 0

The information below is provided by Mister Merit Badge Jr., a scout, with the purpose of helping other scouts understand the steps he had to take to complete the specific requirement.

Programming Requirement 5b: With your counselor’s approval, choose a second programming language and development environment, different from those used for requirement 5a and in a different industry from 5a. Then write, debug, and demonstrate a functioning program to your counselor, using that language and environment.

To do this requirement, I used the website repl.it, and choose the programming language Ruby.

I talked about repl.it in my post about Programming Requirement 5a, I highly recommend using it if you are doing the programming merit badge.

I started by reading examples of Ruby code to see how to write the code, I used both Google and repl.it for all of my research. I started with a “Hello World” program to show me how to output text and how the language was structured. Then I looked at how inputs were handled. Then I was ready to write my code. I wanted my program to guess the year the user was born, by having the user enter their age and then subtract their age from the current year.

I had to find a way to determine the current year in Ruby. Through Google, I found at least 4 different ways to get the the year in Ruby, and I picked one. After I had the year, I ran into a problem when I was subtracting the age from the year. At first I thought there was a problem where Ruby wasn’t treating the year as a number and I kept working on the code but had no luck I always got the same error. I finally Googled the error message and found a person with the exact same problem as me, They had a different program, but same type of scenario and error message. It turned out that the user input was a string not a number (similar to a program I ran into in Programming Requirement 5a), so I researched in Google how to convert a string to an integer in Ruby and once I learned how I was able to fix my code!

After I completed my code, I decided to go back and learn how to put notes, or “comments” into my code so someone reading the code would understand exactly what each line of code did.

If you’d like to see the program I wrote, you can see it below or at https://repl.it/@ekeown/NKRequirement5b.

Leave a Reply

Your email address will not be published.