Skip to content

Conversation

brendarios
Copy link

Calculator exercise

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? In variables
How did you determine what operation to perform? Through a user input and checking if it is included in a predetermined array to make sure the operation was valid
Do you feel like you used consistent indentation throughout your code? I constantly used command i and at the end before submitting I selected all my program and went through Edit - Lines - Autoindent.
If you had more time, what would you have added to or changed about the program? I would probably add a restriction inside the loop that checks if the user inputs (num1 and num2) are a numeric expression so that in case they were not a numeric expression, the program may only give 3 more attempts to enter a correct value, just as I did in the loop that checks if the user input of the type of calculation he wanted to do, where he is restricted to enter 3 more attempts only.

@droberts-sea
Copy link

Calculator

What We're Looking For

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

Great job overall! I have a couple of inline comments below that you should check out, but in general I am quite happy with this submission. Keep up the hard work!


def numberic?(string)
/[%\+\*\d]/.match(string)
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the spelling you're looking for here is numeric?.

def type?(input)
if /\A\d+\z/.match(input)
return "integer"
elsif /\A\d+\.\d+\z/.match(input)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like that you've split all these off into helper methods - good organization!

# this will allow the program to know if the result should be printed as a float or an integer
if type?(num1) == "float"
results.to_f
elsif type?(num1) == "integer" && type?(num2) == "integer"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional could be simplified a bit:

if type?(num1) == "integer" && type?(num2) == "integer"
  results.to_i
else
  results.to_f
end

Also, you're turning result into an integer or a float here, but you don't do anything with the modified value.

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