Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ruby language please Debug Task Step 1: Fix the code so that it works correctly. The sample output is as follows (you may need to

Ruby language please Debug Task

Step 1: Fix the code so that it works correctly. The sample output is as follows (you may need to see the hints below to help you): Remember: 1. .to_s converts a type to a string. 2. .to_i converts an integer in string form to numeric form. 3. require date includes the date library. 4. .chomp removes whitespace from a string (eg: newlines, tabs, spaces).

require 'date'

# Fix up the following code that it works and produces the expected output # in the task specification.

# Asks the user to enter their age and returns an integer age def get_age() puts "Enter your age in years: " age_in_years = gets.to_i return age_in_years end

# takes a prompt and displays it to the user then returns the # entered string def get_string(prompt) puts prompt s = gets.chomp return s end

# Calculate the year born based on the parameter age and print that out # along with the name of the user def print_year_born(age,name) year_born = Date.today.year.to_i - age.to_i puts "#{name.to_s} you were born in: #{year_born.to_s}" end

def main age = get_age() age = age.to_i name = get_string('Enter your name: ') name = name.to_s print_year_born(age,name) end

main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

8. Provide recommendations for how to manage knowledge.

Answered: 1 week ago

Question

5. Develop a self-management module for a training program.

Answered: 1 week ago