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

Create calculator.rb #45

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

Conversation

sarashahbaig
Copy link

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
What went well in your code style, such as indentation, spacing, variable names, readability, etc.? What was lacking? calculation the two number with the operator went really well while coding, except the zero division part was difficult and took time to figure out what was lacking.
How did your code keep track of user input? My code store the user inputs in three different variable ,maths_operator, num_one and num_two.
How did your code determine what operation to perform? My code prompt user to input the operator and it perform only if the operator is available in the array called math_operators or else it will ask the user to "Please enter a math operater:" using until loop.
What opportunities exist to create small methods for this project? I think it would been good if i could used a method on my rescue clause where it could have been shorter by just calling it for the time i wanted instance of writing the same code again.
In the next project, what would you change about your process? What would you keep doing? I would like to try to make my code shorter, I have used rescue clause more than one time so I would keep trying to do something where i can make the code shorter but get the same result.

@tildeee
Copy link
Collaborator

tildeee commented Aug 9, 2019

Calculator

What We're Looking For

Feature Feedback
Readable code with consistent indentation x
Practices using variables appropriately x
Practices using conditionals appropriately x
If any, practices iteration appropriately x
If any, practices using custom methods appropriately this submission did not have any methods
Takes in two numbers and an operator and can perform addition x
Takes in two numbers and an operator and can perform subtraction x
The program handles divide when attempting to divide by zero x

Well done on this project, Sara! Your code works well and reads well.

If you had more time on this project, I would encourage you to consider two things:

  1. Refactor the if ... elsif section to a case/when statement
  2. Find opportunities to create methods

I've also added some comments about small suggestions on how to improve your code.

That being said, you did well on this. Good work!


# ask user to input an maths operater until its valid
until math_operators.include?(math_operater)
puts"Invalid math operator! Please try again."
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 very minor, but I like having spaces inbetween my methods and strings, so I'd like a space between puts and the string, like puts "Invalid math operator!"

num_one = Integer(gets.chomp)
rescue ArgumentError => e
puts "You did not enter a a number. Try again!"
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, I'm looking at this above begin ... rescue section. You end up having this exact logic down below, inside of an until loop... What happens if we replace this above logic with this?

print "Please enter the first number: "
num_one = Integer(gets.chomp) 

num_one = Integer(gets.chomp)
rescue ArgumentError => e
puts "You did not enter a a number. Try again!"
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

We will get into begin ... rescue clauses in-depth later in the program! For now, this is an okay solution, but it may be interesting to consider what it would look like without using the begin ... rescue

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