-
Notifications
You must be signed in to change notification settings - Fork 42
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
pipes-Mariana-Calculator.rb #39
base: master
Are you sure you want to change the base?
Conversation
CalculatorWhat We're Looking For
Great work overall! |
@@ -0,0 +1,59 @@ | |||
def r_or_z(n) | |||
if n.include?(".") | |||
return n.to_f |
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 is a clever way to figure out what's needed here.
|
||
symbol="unvalid" | ||
|
||
while symbol !="valid" do |
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.
I like the idea of using a variable to track whether the loop has to restart. As long as there's only two possibilities (valid and invalid), it's common to use a boolean in this role, something like:
valid_symbol = false
while !valid_symbol do
# ...
while n2==0 do | ||
puts "It is no possible to divide by 0. Please enter a valid number" | ||
n2=gets.chomp | ||
n2=r_or_z(n2) |
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.
Watch your spacing here. Good style is usually to put a space on either side of an equals sign or operator, like n2 = gets.chomp
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions