Skip to content

Melissa - Calculator - Edges#44

Open
melicious-dish wants to merge 1 commit intoAda-C10:masterfrom
melicious-dish:master
Open

Melissa - Calculator - Edges#44
melicious-dish wants to merge 1 commit intoAda-C10:masterfrom
melicious-dish:master

Conversation

@melicious-dish
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 as strings for the first prompt, and as floats when I needed numbers from the user
How did you determine what operation to perform? I began with to use an until statement, but I realized that an array would be better to store the calculations. I wanted to DRY so I played around with creating methods,
Do you feel like you used consistent indentation throughout your code? Yes, but I think I could have used more methods for the user input for more DRYness
If you had more time, what would you have added to or changed about the program? Again, I could have created more methods for the "Give me 2 #'s..."

@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

Good job overall! You've done a good job of organizing and breaking up your code using methods and whitespace. There are a couple of places where things could be cleaned up, which I've tried to call out inline below, but in general I am quite happy with this submission. Keep up the hard work!


if user_input == "add" || user_input == "+"
puts "Give me 2 #'s': "
print "#1: "

Choose a reason for hiding this comment

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

Watch your indentation here.

def get_user_num
user_num = gets.chomp
until user_num =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
print "Not a valid number. Try again: "

Choose a reason for hiding this comment

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

Good use of methods here to break this code up and make it readable.

elsif user_input == "subtract" || user_input == "-"
puts "Give me 2 #'s': "
print "#1: "
num_1 = get_user_num()

Choose a reason for hiding this comment

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

You touched on this in your answers to the comprehension questions, but you've got the same code copy-pasted several times here. You could use a method to DRY this up, but the better thing to do might be to move the work to before the if.

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