Skip to content

Conversation

@larachan15
Copy link

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? I stored user input by first getting their input with gets.chomp and then assignment that input to a variable.
How did you determine what operation to perform? After getting the user input on which operator they wanted to use, I used a case statement.
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 used one puts statement to do the calculations at the end instead of doing them inside each case statement.

@tildeee
Copy link
Collaborator

tildeee commented Aug 12, 2018

Calculator

What We're Looking For

Feature Feedback
Takes in two numbers and an operator and performs the mathematical operation. oh no! it's broken!
Readable code with consistent indentation. x

Hello Dionisia!

Oh no! Your code didn't run when I looked at it.

On running this code as is, it looks for a method valid_operators on line 26. There is no method named valid_operators in this file!

Let's say that I change line 26 to

user_entry = gets.chomp.downcase

With this change, it doesn't check if the operator is valid, but it'll at least move forward.

Then, the code gets stuck -- no matter what input you give it for the numbers, it will always believe that your input is not a number and print "I need a number please!".

Well, the problem is in how you validate the number... you validate the number by calling the method valid_num. Well, in this file, valid_num is defined twice! It will take the last definition of the method, so it's going to check if the numbers are Integers, not Floats.

By removing the call to valid_operators and deleting the other implementation of valid_num, the code works as expected. It doesn't check the validity of the operator, but otherwise it looks good.

Good work -- next time check that your code runs before submitting ;)

when "divide", "/"
div_total = num1 / num2
puts "#{num1} / #{num2} = #{div_total}"
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm being nitpicky, but this end should be on the same indentation as case (so, one less indentation). not a big deal, just a small note!


# Verifying valid operators have been selected
def valid_num(number)
until (true if Float(number) rescue false)
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general, this reads kind of funny. Also, number will always be a float, since you get number from the call gets.chomp.to_f, which converts them to floats all the time.

Overall, the code works, but is just a little funny -- I wouldn't call this a high priority thing to correct, but something to return to in a few days or weeks with fresh eyes.

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