Skip to content

Angela Hu - Calculator - Octos - #18

Open
knockknockhusthere wants to merge 1 commit into
Ada-C9:masterfrom
knockknockhusthere:master
Open

Angela Hu - Calculator - Octos#18
knockknockhusthere wants to merge 1 commit into
Ada-C9:masterfrom
knockknockhusthere:master

Conversation

@knockknockhusthere

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 variable
How did you determine what operation to perform? I ran through a case statement to compare against user's inputted operator string.
Do you feel like you used consistent indentation throughout your code? It got a little crazy re-factoring towards the end, but yes it should be consistent
If you had more time, what would you have added to or changed about the program? I would see that the program knows when to return a float or an integer. Also I would have familiarized myself with regex and used that instead.

@CheezItMan

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, although you've got some bugs, see my inline comments.
Readable code with consistent indentation. Some small indentation errors, minor things, overall it's good.
Summary You hit all the primary requirements and you also added exponentiation and modulus. Check my inline comments for specific feedback. Well done.

Comment thread calculator.rb

#method within the string class that returns false if element cannot be converted into a float
class String
def valid_float?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a technique known as a mix-in. Neat that you used it here.

Comment thread calculator.rb


#checks that operator matches something from the array of operators
until (ops_symbol.include? user_operator) || (ops_spelled.include? user_operator)

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 could make an array with both the symbols and spelled out operators.

Comment thread calculator.rb
puts "Sorry. You can't divide by zero! Please choose something else. "
puts "Please enter a second number: "
user_num2 = gets.chomp
while user_num2.valid_float? == false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This won't keep them from entering a 0 the second time around.

Comment thread calculator.rb
end

#does not let the user divide by 0, re-prompts for the second number
if (user_operator == "/" or user_operator == "divide") && user_num2 == 0

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 haven't converted user_num2 to an integer or float here first. This would need to be:

if (user_operator == "/" || user_operator == "divide") && user_num2.to_f == 0

Comment thread calculator.rb

#does not let the user divide by 0, re-prompts for the second number
if (user_operator == "/" or user_operator == "divide") && user_num2 == 0
puts "Sorry. You can't divide by zero! Please choose something else. "

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 also indented a bit much here. In general indent either one tab or two spaces, just do it consistently.

Comment thread calculator.rb


#case statement to decide which operator function to call
case user_operator

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is indented when it shouldn't be.

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