Created
July 9, 2018 09:49
-
-
Save volpeo/46b290acc1c03da3fd38f5fe73aecc5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process_calculation(first_number, second_number, operator) | |
first_number.send(operator, second_number) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "calculator" | |
operators = ["+", "-", "*", "/", "%", "**"] | |
user_input = "Y" | |
while user_input == "Y" | |
puts "First number?" | |
first_number = gets.to_i | |
puts "Choose operator: #{operators.join(', ')}" | |
operator = gets.chomp | |
puts "Second number?" | |
second_number = gets.to_i | |
if operators.include? operator | |
result = process_calculation(first_number, second_number, operator) | |
puts "Result: #{result}" | |
else | |
puts "ERROR: You can use only #{operators.join(', ')}" | |
end | |
puts "Do you want to continue? (Y/N)" | |
user_input = gets.upcase[0] | |
end | |
puts "Goodbye" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment