Skip to content

Brandy Austin - Calculator - Octos#19

Open
brandyaustinseattle wants to merge 3 commits into
Ada-C9:masterfrom
brandyaustinseattle:master
Open

Brandy Austin - Calculator - Octos#19
brandyaustinseattle wants to merge 3 commits into
Ada-C9:masterfrom
brandyaustinseattle:master

Conversation

@brandyaustinseattle

Copy link
Copy Markdown

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? I stored user input in a hash with operation, num_1, num_2 as the keys.
How did you determine what operation to perform? I created a hash of arrays where the elements of the arrays represented the valid entries for each operation.
Do you feel like you used consistent indentation throughout your code? Yes.
If you had more time, what would you have added to or changed about the program? I would have added support for exponential functions and modular functions. I would have also edited the functionality so that the calculator logged all requested calculations. Finally, I would have made it so that the user could have performed multiple calculations without needing to re-run the program.

@droberts-sea

Copy link
Copy Markdown

Calculator

What We're Looking For

Feature Feedback
Takes in two numbers and an operator and performs the mathematical operation. yes
Readable code with consistent indentation. yes

Great job overall! I have a couple of inline comments below that you should check out, but in general I am quite happy with this submission. Keep up the hard work!

Comment thread calculator.rb
# perform addition
def addition(num_1, num_2)
num_1 + num_2
return num_1 + num_2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are redundant - you should be able to get away with only the second.

Comment thread calculator.rb
# format_userinput_not_including_division formats the numbers, but doesn't perform the calculation
def format_userinput_for_division(operator, valid_operators, num_1, num_2, user_input)
if num_1 =~ /^(\d)+$/ && num_2 =~ /^(\d)+$/
unless divide_by_zero(num_2.to_i)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the user_input include num_1, num_2 and the operator?

Comment thread calculator.rb
# request operation, num_1, and num_2 from user then store in hash
def request_operations_numbers(user_input, valid_operators)
puts "What operation would you like to perform?"
operation = gets.chomp

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this a little in person, but I'll recap here:

I like that you've broken this out as a separate method, but passing all the user input around as a hash is a little unwieldy. Another possible approach is to have one method to read a number, which is called twice, and another to read the operator.

Comment thread calculator.rb
# only formats the numbers, does not perform the actual calculation
def format_userinput_not_including_division(valid_operators, num_1, num_2, user_input)
if num_1 =~ /^(\d)*\.(\d)+$/
num_1 = num_1.to_f

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have the same code repeated twice in this function, the only difference being num_1 or num_2. Is there a way you could consolidate this?

Maybe change it to be a method that takes one number in string form, and returns that number as an int or float as appropriate.

Comment thread calculator.rb
format_userinput_not_including_division(valid_operators, user_input[:num_1], user_input[:num_2], user_input)
result = addition(user_input[:num_1], user_input[:num_2])
result = format_if_result_is_zero(result)
puts "#{user_input[:num_1]} + #{user_input[:num_2]} = #{result}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These last two lines (calling format_if_result_is_zero and putsing) are almost the same for every operation. Could you eliminate this redundancy somehow?

@brandyaustinseattle brandyaustinseattle changed the title Brandy Austin's Calculator Project Brandy Austin - Calculator - Octos Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants