Skip to content

Leaves - Nicky #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Leaves - Nicky #51

wants to merge 1 commit into from

Conversation

njch5
Copy link

@njch5 njch5 commented Aug 7, 2019

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
What went well in your code style, such as indentation, spacing, variable names, readability, etc.? What was lacking? Indentation and spacing makes the calculator file readable and variables names are explicitly clear.
What I thought was lacking was for the variable names within the methods, I thought it may be difficult to differentiate between the two variable names (num_one and num_two) especially when they're all the same amongst all the calculation methods.
How did your code keep track of user input? For the operators, I nested case/when statements within a while loop to say if any of the appropriate operators are entered then it would be stored as the user's operator within the variable 'users_operator'. If not, then a message is printed to prompt the user for a valid operator. The message will continue to loop until the user enters a valid input.
For user's number inputs, I used begin/rescue/retry statements which will throw an exception if a user does not enter a valid integer input. I was not able to also check for a float input so I was wondering if that would require additional conditional statements?
How did your code determine what operation to perform? Based on what was stored in the users_operator variable, the series of conditional statements toward the bottom of my code will then determine which method to use for calculations.
What opportunities exist to create small methods for this project? A small method for check for division by zero. Another method for validating user input for numbers.
In the next project, what would you change about your process? What would you keep doing? I would first organize what I'm trying to achieve at a higher level by using pseudocode to break each requirement down in simpler terms so it's easier to comprehend the project objectives. I would continue writing out the variables I need and determine what loops can be used.

Copy link

@beccaelenzil beccaelenzil left a comment

Choose a reason for hiding this comment

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

Your code is clear and makes good use of new concepts (methods, case/when). You have several clever solutions to dealing with invalid user input. See code review for a few minor suggestions on how to make your code more concise.


# Checks and validates user input. If input is not an integer, an exception is thrown and prompts the user to enter a valid number
begin
num_one = Integer(gets.chomp) # Question: Is there a way to accept both integers and floats from the user? Would this require conditional statements?

Choose a reason for hiding this comment

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

Instead of Interger(gets.chomp) you could use Float(gets.chomp). Converting to Floats is a better option so that it performs division correctly (5/2 = 2.5 (as opposed to 2).)


puts "Please enter another number:"

begin

Choose a reason for hiding this comment

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

Consider using a loop to DRY up your code.

retry
end

# Performs calculations based on user input

Choose a reason for hiding this comment

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

The is a clever use of begin/rescue/retry. Nice research!

end

# Performs calculations based on user input
if users_operator == "ADD" || users_operator == "+"

Choose a reason for hiding this comment

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

Consider using a case/when block to simplify your code.

puts "Please choose one operator(name or symbol):"

# Stores user's input as one of the operators or prints a message telling them to enter a valid operator
while users_operator = gets.chomp.upcase

Choose a reason for hiding this comment

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

This is clever -- however an includes? method would simplify this operation:

until [array of valid operations].includes?(users_operator)

@beccaelenzil
Copy link

Calculator

What We're Looking For

Feature Feedback
Readable code with consistent indentation yes
Practices using variables appropriately yes
Practices using conditionals appropriately yes
If any, practices iteration appropriately yes
If any, practices using custom methods appropriately yes
Takes in two numbers and an operator and can perform addition yes
Takes in two numbers and an operator and can perform subtraction yes
The program handles divide when attempting to divide by zero yes

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