From 627898d0bb89348b4477f9d7bf1bfc11af1c0f89 Mon Sep 17 00:00:00 2001 From: CheerOnMars <36147056+CheerOnMars@users.noreply.github.com> Date: Tue, 6 Feb 2018 17:00:59 -0800 Subject: [PATCH 1/3] Create wk1_calc.rb --- wk1_calc.rb | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 wk1_calc.rb diff --git a/wk1_calc.rb b/wk1_calc.rb new file mode 100644 index 0000000..18786f7 --- /dev/null +++ b/wk1_calc.rb @@ -0,0 +1,2 @@ +#Calculator Exercise + From b61fdbf63af7a0ed8d8ba319bbc08d524b5ccd7c Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Wed, 7 Feb 2018 10:24:35 -0800 Subject: [PATCH 2/3] My Calculator --- wk1_calc.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/wk1_calc.rb b/wk1_calc.rb index 18786f7..ac0b505 100644 --- a/wk1_calc.rb +++ b/wk1_calc.rb @@ -1,2 +1,48 @@ #Calculator Exercise +#command line interface that allows a user to perform simple arithmetic +puts "This calculator will perform simple arithmetic on two numbers, using either addition, subtraction, multiplication, or division." +puts + +operation_attempts = 0 +#number1_attempts = 0 +#number2_attempts = 0 + +print "What is the first number? " +num_one = gets.chomp.to_f + +print "What is the second number? " +num_two = gets.chomp.to_f + +print "Which operation would you like performed? " +command = gets.chomp.upcase.to_s + +until ["ADD", "+", "SUBTRACT", "-", "MULTIPLY", "*", "DIVIDE", "/"].include?(command) + operation_attempts += 1 + puts "You did not enter an available operation. Please try again." + command = gets.chomp.upcase.to_s +end + +puts command +puts operation_attempts + +case command + when "ADD", "+" + puts "We're adding numbers" + puts num_one + num_two + when "SUBTRACT", "-" + puts "We're subtracting numbers" + puts num_one - num_two + when "MULTIPLY", "*" + puts "We're multiplying numbers" + puts num_one * num_two + when "DIVIDE", "/" + puts "We're dividing numbers" + puts num_one / num_two + else + puts "You did not enter an available operation. Please try again." +end + + +#Bike rack for future enhancements +#av_commands = ["ADD", "+", "SUBTRACT", "-", "MULTIPLY", "*", "DIVIDE", "/"] From 917e129aeeb8317cf8bbdff43eef01c8549aa067 Mon Sep 17 00:00:00 2001 From: CheerOnMars <36147056+CheerOnMars@users.noreply.github.com> Date: Thu, 8 Feb 2018 08:20:10 -0800 Subject: [PATCH 3/3] Update calculator --- wk1_calc.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/wk1_calc.rb b/wk1_calc.rb index ac0b505..bb9c0ab 100644 --- a/wk1_calc.rb +++ b/wk1_calc.rb @@ -4,10 +4,6 @@ puts "This calculator will perform simple arithmetic on two numbers, using either addition, subtraction, multiplication, or division." puts -operation_attempts = 0 -#number1_attempts = 0 -#number2_attempts = 0 - print "What is the first number? " num_one = gets.chomp.to_f @@ -18,13 +14,11 @@ command = gets.chomp.upcase.to_s until ["ADD", "+", "SUBTRACT", "-", "MULTIPLY", "*", "DIVIDE", "/"].include?(command) - operation_attempts += 1 puts "You did not enter an available operation. Please try again." command = gets.chomp.upcase.to_s end puts command -puts operation_attempts case command when "ADD", "+"