Skip to content

katrina_edges_calculator#40

Open
kaganon wants to merge 1 commit intoAda-C10:masterfrom
kaganon:master
Open

katrina_edges_calculator#40
kaganon wants to merge 1 commit intoAda-C10:masterfrom
kaganon:master

Conversation

@kaganon
Copy link

@kaganon kaganon commented Aug 8, 2018

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 my program using variables and assigning the variables into the parameters of my methods.
How did you determine what operation to perform? I stored the name/symbol of operators into an array and used a conditional to determine if the user input is included in that array.
Do you feel like you used consistent indentation throughout your code? Yes, I think so
If you had more time, what would you have added to or changed about the program? I think I would have also added the modulo method to determine if the output will be an integer or float. I also would have liked to get a better method other than regex to handle if the user input number was actually a number or random character.

@kaganon kaganon changed the title Katrina - Calculator - Edges Katrina_Edges_calculator.rb Aug 8, 2018
@kaganon kaganon changed the title Katrina_Edges_calculator.rb katrina_edges_calculator.rb Aug 8, 2018
@kaganon kaganon changed the title katrina_edges_calculator.rb katrina_edges_calculator Aug 8, 2018
@droberts-sea
Copy link

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! This program works well, and I like the way you've used methods and whitespace to break up your code. There are a few places that things could be cleaned up, which I've tried to call out below, but in general I am quite happy with this submission. Keep up the hard work.

until second_number.match?(/^(?=.*[\d])/) ||
second_number.match?(/^(?=.*[-])(?=.*[\d])/)
puts "Hm, something went wrong..."
print "Please enter your second number: "

Choose a reason for hiding this comment

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

You've written almost exactly the same code here twice, to get the first number and the second number. Could you DRY that up by putting this logic in a method?

case user_symbol
when "add", "+"
sum = add_numbers(first_number, second_number)
puts "#{first_number} + #{second_number} = #{sum}"

Choose a reason for hiding this comment

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

This code isn't repeated, but I think it would still increase readability to wrap this case/when section in a method. That would clearly delineate where it starts and ends, and make it explicit what data it needs to work. The method signature might be something like perform_calculation(op, first, second).

when "divide", "/"
if second_number == 0
puts "Undefined - cannot divide a number by zero"
else

Choose a reason for hiding this comment

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

Could you put this division-specific error handling code in the division method?

# Addition method
def add_numbers(num1, num2)
return num1 + num2
end

Choose a reason for hiding this comment

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

I like that you've broken each of these operations out as its own method, and that you're returning a value rather than putsing it here.

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