Question
Implement a main procedure with the following logic: It reads a name from the user, and displays back a message. Check if the name entered
Implement a main procedure with the following logic:
It reads a name from the user, and displays back a message.
Check if the name entered is your name or your tutor's name.
If the name is your name or your tutors name output the message: '#{name} is an awesome name!'
Otherwise output the silly name message: '#{name} is a silly name
Please provide an adequate response or be subject to a report. Ty
Provided code:
name_tester.rb
require './input_functions'
# write code that reads in a user's name from the terminal. If the name matches
# your name or your tutor's name, then print out "
# Otherwise call a function called print_silly_name(name) - to match the expected output.
#def print_silly_name(name)
#
#end
def main
name = read_string("What is your name?")
if name == "Ted" or name == "Fred"
puts name + " is an awesome name!"
else
puts(name + " is a silly name")
end
end
main input_functions.rb:
# Display the prompt and return the read string
def read_string prompt
puts prompt
value = gets.chomp
end
# Display the prompt and return the read float
def read_float prompt
value = read_string(prompt)
value.to_f
end
# Display the prompt and return the read integer
def read_integer prompt
value = read_string(prompt)
value.to_i
end
# Read an integer between min and max, prompting with the string provided
def read_integer_in_range(prompt, min, max)
value = read_integer(prompt)
while (value max)
puts "Please enter a value between " + min.to_s + " and " + max.to_s + ": "
value = read_integer(prompt);
end
value
end
# Display the prompt and return the read Boolean
def read_boolean prompt
value = read_string(prompt)
case value
when 'y', 'yes', 'Yes', 'YES'
true
else
false
end
end
# Test the functions above
=begin
def main
puts "String entered is: " + read_string("Enter a String: ")
puts "Boolean is: " + read_boolean("Enter yes or no:").to_s
puts "Float is: " + read_float("Enter a floating point number: ").to_s
puts "Integer is: " + read_integer_in_range("Enter an integer between 3 and 6: ", 3, 6).to_s
end
main
=end
Implement a main procedure with the following logic: - It reads a name from the user, and displays back a message. - Check if the name entered is your name or your tutor's name. - If the name is your name or your tutor's name output the message: '\#\{name } is an awesome name!' - Otherwise output the silly name message: '\#\{name\} is a silly name
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started