Angela Hu - Calculator - Octos - #18
Conversation
CalculatorWhat We're Looking For
|
|
|
||
| #method within the string class that returns false if element cannot be converted into a float | ||
| class String | ||
| def valid_float? |
There was a problem hiding this comment.
This is a technique known as a mix-in. Neat that you used it here.
|
|
||
|
|
||
| #checks that operator matches something from the array of operators | ||
| until (ops_symbol.include? user_operator) || (ops_spelled.include? user_operator) |
There was a problem hiding this comment.
You could make an array with both the symbols and spelled out operators.
| puts "Sorry. You can't divide by zero! Please choose something else. " | ||
| puts "Please enter a second number: " | ||
| user_num2 = gets.chomp | ||
| while user_num2.valid_float? == false |
There was a problem hiding this comment.
This won't keep them from entering a 0 the second time around.
| end | ||
|
|
||
| #does not let the user divide by 0, re-prompts for the second number | ||
| if (user_operator == "/" or user_operator == "divide") && user_num2 == 0 |
There was a problem hiding this comment.
You haven't converted user_num2 to an integer or float here first. This would need to be:
if (user_operator == "/" || user_operator == "divide") && user_num2.to_f == 0
|
|
||
| #does not let the user divide by 0, re-prompts for the second number | ||
| if (user_operator == "/" or user_operator == "divide") && user_num2 == 0 | ||
| puts "Sorry. You can't divide by zero! Please choose something else. " |
There was a problem hiding this comment.
You have also indented a bit much here. In general indent either one tab or two spaces, just do it consistently.
|
|
||
|
|
||
| #case statement to decide which operator function to call | ||
| case user_operator |
There was a problem hiding this comment.
This is indented when it shouldn't be.
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions