-
Notifications
You must be signed in to change notification settings - Fork 44
Jackie Onofre - Calculator - Amper #39
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
base: master
Are you sure you want to change the base?
Conversation
CalculatorWhat We're Looking For
|
|
|
||
| # Method to determine whether input is numeric | ||
| def numeric(num) | ||
| if num =~ /[-+]?([0-9]*\.[0-9]+|[0-9]+)/ |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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).
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions