Skip to content

Conversation

arrriiii
Copy link

@arrriiii arrriiii commented Feb 7, 2018

calculator project

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? I used regex to check the users inputs were valid numbers (omitting commas)
How did you determine what operation to perform? I used an array with operator names & symbols to confirm the users response.. that response would use the associated method and return the operation.
Do you feel like you used consistent indentation throughout your code? yes except I wasn't sure if the spacing for methods was correct
If you had more time, what would you have added to or changed about the program? I would liked to accept commas for larger number using a format method... of some sort.

@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

In response to your PR comments, the spacing on your methods works fine, but where you've defined them is a little odd - see below. For large numbers, commas are a little tricky but you can use underscores instead: "1_234".to_i will produce 1234.

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!

# divide
def divide(num1, num2)
if num2 != 0

Choose a reason for hiding this comment

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

This divide method is defined inside your while loop! While this is technically valid Ruby (and certainly works), it's a little odd to me as a reader. A better option might be to define all your methods at the very top of the file, and have your main control loop below that.

def multiply(num1, num2)

print "#{num1} * #{num2} = "
(num1 * num2).round(2)

Choose a reason for hiding this comment

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

Printing out the equation inside the method is one way to solve this optional, but it's not always ideal, because it means your method is doing two different things: doing some math problem, and printing an equation. This takes control away from whoever's calling your method. There's no way to do multiplication without also putsing something to the screen.

In general, you should try to make your methods do only one thing.

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