From 87f3635269b64bb947a1ebfc4cb353ab62708f1b Mon Sep 17 00:00:00 2001 From: cecomfort Date: Thu, 9 Feb 2017 21:39:44 -0800 Subject: [PATCH 1/2] Create Queues - Cara Comfort- Calculator --- Queues - Cara Comfort- Calculator | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Queues - Cara Comfort- Calculator diff --git a/Queues - Cara Comfort- Calculator b/Queues - Cara Comfort- Calculator new file mode 100644 index 0000000..3bfea13 --- /dev/null +++ b/Queues - Cara Comfort- Calculator @@ -0,0 +1,58 @@ +def add(num_one, num_two) + return num_one + num_two +end + +def subtract(num_one, num_two) + return num_one - num_two +end + +def multiply(num_one, num_two) + return num_one * num_two +end + +def divide(num_one, num_two) + if num_two == 0 + return "#{num_one} is not divisible by 0" + else + return num_one / num_two + end +end + +def convert_to_num(num) + until num.to_f.to_s == num || num.to_i.to_s == num + print "Please input a number: " + num = gets.chomp + end + + if num.include? "." + return num.to_f + else + return num.to_i + end +end + + +print "\nWhat operation would you like to perform? " +operation = gets.chomp +possible_operators = ["add", "+", "subtract", "-", "multiply", "*", "divide", "/"] +until possible_operators.include?(operation) + print "Please tell me to add (+), subtract (-), multiply (*) or divide (/): " + operation = gets.chomp +end + +print "\nWhat is your first number? " +num_one = convert_to_num(gets.chomp) + +print "\nWhat is your second number? " +num_two = convert_to_num(gets.chomp) + +case operation +when "add", "+" + puts add(num_one, num_two) +when "subtract", "-" + puts subtract(num_one, num_two) +when "multiply", "*" + puts multiply(num_one, num_two) +when "divide", "/" + puts divide(num_one, num_two) +end From eb1829924da1cde44838bf77375a24d66297aa28 Mon Sep 17 00:00:00 2001 From: cecomfort Date: Thu, 9 Feb 2017 21:43:30 -0800 Subject: [PATCH 2/2] Create calculator.rb --- calculator.rb | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 calculator.rb diff --git a/calculator.rb b/calculator.rb new file mode 100644 index 0000000..3bfea13 --- /dev/null +++ b/calculator.rb @@ -0,0 +1,58 @@ +def add(num_one, num_two) + return num_one + num_two +end + +def subtract(num_one, num_two) + return num_one - num_two +end + +def multiply(num_one, num_two) + return num_one * num_two +end + +def divide(num_one, num_two) + if num_two == 0 + return "#{num_one} is not divisible by 0" + else + return num_one / num_two + end +end + +def convert_to_num(num) + until num.to_f.to_s == num || num.to_i.to_s == num + print "Please input a number: " + num = gets.chomp + end + + if num.include? "." + return num.to_f + else + return num.to_i + end +end + + +print "\nWhat operation would you like to perform? " +operation = gets.chomp +possible_operators = ["add", "+", "subtract", "-", "multiply", "*", "divide", "/"] +until possible_operators.include?(operation) + print "Please tell me to add (+), subtract (-), multiply (*) or divide (/): " + operation = gets.chomp +end + +print "\nWhat is your first number? " +num_one = convert_to_num(gets.chomp) + +print "\nWhat is your second number? " +num_two = convert_to_num(gets.chomp) + +case operation +when "add", "+" + puts add(num_one, num_two) +when "subtract", "-" + puts subtract(num_one, num_two) +when "multiply", "*" + puts multiply(num_one, num_two) +when "divide", "/" + puts divide(num_one, num_two) +end