Skip to content

Layla_Edges_Calculator.rb#49

Open
lbristol88 wants to merge 1 commit into
Ada-C10:masterfrom
lbristol88:master
Open

Layla_Edges_Calculator.rb#49
lbristol88 wants to merge 1 commit into
Ada-C10:masterfrom
lbristol88:master

Conversation

@lbristol88

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 by assigning their responses into four variables:, user_input, first_number, second_number and play_again.
How did you determine what operation to perform? To determine what operation to perform, I used an until loop that requires the user to enter in one of the pre-determined options, and once they input their valid operator of choice , the program requests them to enter in their two numbers to perform the operator action on.
Do you feel like you used consistent indentation throughout your code? I feel like I used consistent indentation throughout my code. I used a nested if statement within my case statement. My program is also within a while statement.
If you had more time, what would you have added to or changed about the program? I would have tried to create a method to store the operator options and reduce the amount of text in the code during the case statement.

@droberts-sea

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
Readable code with consistent indentation. yes

Good work overall. This program works well, and I like the way you've broken up your code with withespace - this makes it much easier to read. I would definitely like to see you working with methods more - make sure you take the opportunity to practice with these as we work through the data transformation worksheet and RideShare. Other than that I am pretty happy with this submission - keep up the hard work.

Comment thread calculator.rb
# verifies if user enters in one of the defined options and if not, asks the user to re-enter their choice.
until %[add + subtract - multiply * divide /].include?(user_input)
print "Your input is invalid. Please try again. "
user_input = gets.chomp

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'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?

Comment thread calculator.rb
# which operator is selected, the calculation is completed and displayed for the user.
case user_input

when "add", "+"

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 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(user_input, first_number, second_number).

Comment thread calculator.rb

# prompts the user to select which operator option they'd like to use.
print "Please choose one operator (name or symbol): "
user_input = gets.chomp

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think there might be a more specific name for this variable than user_input, since there are several pieces of user input in this program. Something like operation might be a better choice.

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