Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lmarianarp19
Copy link

@lmarianarp19 lmarianarp19 commented Aug 11, 2017

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program. I stored with variables
How did you determine what operation to perform? I checked with if statements. For the sum for example I checked if the user enter "+" or "add".
How did you make sure your program behaved correctly? I tried with many values, with integers, real numbers, trying to divide by 0, etc.
Do you feel like you used consistent indentation throughout your code? Yes
If you had more time, what would you have added to or changed about the program? I would finish all the optionals enhancements. Specially if the user enter a letter instead a number.

@droberts-sea
Copy link
Collaborator

Calculator

What We're Looking For

Feature Feedback
Takes in two numbers and an operator and performs the mathematical operation. Yes
Baseline
Readable code with consistent indentation. Yes

Great work overall!

@@ -0,0 +1,59 @@
def r_or_z(n)
if n.include?(".")
return n.to_f
Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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

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