Conversation
beccaelenzil
left a comment
There was a problem hiding this comment.
Great work incorporating methods to write clean and concise code. Your answers to the reflection questions are thorough and thoughtful. See the code review for minor suggestions for DRYing up your code and simplifying some conditional control structures.
|
|
||
| puts "\nAttention! This CALCULATOR works with two numbers at a time." | ||
|
|
||
| print "Please input the FIRST number: " |
There was a problem hiding this comment.
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 and/or a loop?
| # handle divide when attempting to divide by zero (just exit the program). | ||
| # make your program know when it needs to return an integer versus a float. | ||
|
|
||
| if option == "add" || option == "+" |
There was a problem hiding this comment.
Consider using a case/when block to simplify your code.
|
|
||
| print "Please input the FIRST number: " | ||
| num1 = gets.chomp | ||
| while (num1.to_i.to_s != num1.strip) |
There was a problem hiding this comment.
This is a clever way to check for valid user input
|
|
||
| operations = ["add", "+", "subtract", "-", "multiply", "*", "divide", "/"] | ||
|
|
||
| print "\nPlease choose one operator (name or symbol): " |
There was a problem hiding this comment.
Using while and include? is a great way to check for valid user input.
CalculatorWhat We're Looking For
|
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions