From 5d8138c1cabae6e96131d59dc11214a701ad7d67 Mon Sep 17 00:00:00 2001 From: Faezeh Ashtiani <55011300+faezeh-ashtiani@users.noreply.github.com> Date: Wed, 5 Feb 2020 10:26:53 -0800 Subject: [PATCH 1/2] Create faezeh_calculator.rb --- faezeh_calculator.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 faezeh_calculator.rb diff --git a/faezeh_calculator.rb b/faezeh_calculator.rb new file mode 100644 index 0000000..faea769 --- /dev/null +++ b/faezeh_calculator.rb @@ -0,0 +1,64 @@ +# When a user runs this program, the program should ask the user for the following things: + +# 1- a math operation +# 2- a number for the math operation +# 3- a second number for the math operation + +puts "I am glad you chose my calculator, because it's awesome! +Which operator woudl you like to use? +1. add(+) +2. subtract(-) +3. multiply(*) +4. devide (/) +Please choose one operator (name or symbol)" + +command = gets.chomp.downcase + +# operators = ["add", "+", "subtract", "-", +# "multiply", "*", "devide", "/"] + +# operators.each do |i| +# puts i + "(" #{i+1} + ")" +# end + +until ["add", "+", "subtract", "-", "multiply", "*", "divide", "/", ].include?(command) + puts "What you entered is not an option! + Please tell me to add (+), subtract (-) multiply (*) or devide (/)!" + command = gets.chomp.downcase +end + +class Object + def is_number? + to_f.to_s == to_s || to_i.to_s == to_s + end +end + +num_1_str = "first" +until num_1_str.is_number? + puts "Please provide your first number:" + num_1_str = gets.chomp +end +num_1 = num_1_str.to_f + +num_2_str = "second" +until num_2_str.is_number? + puts "Please provide your second number:" + num_2_str = gets.chomp +end +num_2 = num_2_str.to_f + +case command +when "add", "+" + puts "We're adding numbers" + puts "#{num_1} + #{num_2}: #{num_1 + num_2}" +when "subtract", "-" + puts "We're subtracting numbers" + puts "#{num_1} - #{num_2}: #{num_1 - num_2}" +when "multiply", "*" + puts "We're multiplying numbers" + puts "#{num_1} * #{num_2}: #{num_1 * num_2}" +when "divide", "/" + puts "We're dividing numbers" + puts "#{num_1} / #{num_2}: #{num_1 / num_2}" +end + From 8d5b34e33cf96651b7afda6ad9c80db3dbe45f8e Mon Sep 17 00:00:00 2001 From: Faezeh Ashtiani <55011300+faezeh-ashtiani@users.noreply.github.com> Date: Sat, 8 Feb 2020 17:06:11 -0800 Subject: [PATCH 2/2] Update faezeh_calculator.rb Co-Authored-By: Chris M --- faezeh_calculator.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/faezeh_calculator.rb b/faezeh_calculator.rb index faea769..fbb70ed 100644 --- a/faezeh_calculator.rb +++ b/faezeh_calculator.rb @@ -9,7 +9,7 @@ 1. add(+) 2. subtract(-) 3. multiply(*) -4. devide (/) +4. divide (/) Please choose one operator (name or symbol)" command = gets.chomp.downcase @@ -61,4 +61,3 @@ def is_number? puts "We're dividing numbers" puts "#{num_1} / #{num_2}: #{num_1 / num_2}" end -