Skip to content

Conversation

@Jackiesan
Copy link

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? Stored input in variables (num1 and num2).
How did you determine what operation to perform? 1. I created and array with all acceptable operations. The user input had to match to any of the elements in the array. 2. I created methods for each operation and used if statements to perform corresponding method.
Do you feel like you used consistent indentation throughout your code? Yes, I believe so.
If you had more time, what would you have added to or changed about the program? I would have liked to add the exponential operation. Also, my program currently accepts numbers even if they have letter after them so I would like to make that not valid.

@CheezItMan
Copy link

Calculator

What We're Looking For

Feature Feedback
Takes in two numbers and an operator and performs the mathematical operation. Check
Baseline
Readable code with consistent indentation. Good consistent indentation
Summary Nicely done, you hit all the requirements. Very good use of regex to verify input and you did a pretty good job of breaking things into methods. Well done.


# Method to determine whether input is numeric
def numeric(num)
if num =~ /[-+]?([0-9]*\.[0-9]+|[0-9]+)/

Choose a reason for hiding this comment

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

nice regular expression! Good way to verify something's a number.

num1 = gets.chomp

# User gets message to enter number again if it is not numerical
until numeric(num1)

Choose a reason for hiding this comment

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

Good way to trap the user until they enter a valid number.

end

if operation == "divide" || operation == "/"
until num2 != 0.0

Choose a reason for hiding this comment

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

good catch

until num2 != 0.0
print "Error: Division by zero is undefined. Try another number: "
num2 = gets.chomp
until numeric(num2)

Choose a reason for hiding this comment

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

This looks like a similar operation to what you did before... hmm... this would make a good method (prompting the user for a number and reading it in).

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