Skip to content

Leaves - Samantha#49

Open
iamsammysam wants to merge 2 commits intoAda-C12:masterfrom
iamsammysam:master
Open

Leaves - Samantha#49
iamsammysam wants to merge 2 commits intoAda-C12:masterfrom
iamsammysam:master

Conversation

@iamsammysam
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? I started by including the requirements as comments (pseudocode) and worked from that. Regarding variables I chose simple and short names. I also thought about the user experience by giving a lot of information about the program and feedback. For readability I made "blocks" separated by empty lines of parts of the code that are working on the same data for easy understanding and visualizing.
How did your code keep track of user input? It stores the user input for "operation" "1st number" and "2nd number" in variables.
How did your code determine what operation to perform? It took the user input and by using a loop gave an error message until the "operation symbol or word that describes it (including capital letters or uppercase)" input was included at the array "operations" previously created to check this info. If yes the program use the info to do the math.
What opportunities exist to create small methods for this project? To create a method to get and evaluate user input for the numbers (then the calculator could work later with more than 2 numbers without adding to much code to it) also to create a method for the math operations.
In the next project, what would you change about your process? What would you keep doing? I usually start by designing the program in a simple way that works and after that I use methods and interpolation to make it work with less code. A next step for me will be to create my own methods, use more REGEX and other tools to make the program smaller but still effective.

Copy link

@beccaelenzil beccaelenzil left a comment

Choose a reason for hiding this comment

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

Great work incorporating methods to write clean and concise code. Your answers to the reflection questions are thorough and thoughtful. See the code review for minor suggestions for DRYing up your code and simplifying some conditional control structures.


puts "\nAttention! This CALCULATOR works with two numbers at a time."

print "Please input the FIRST number: "
Copy link

@beccaelenzil beccaelenzil Aug 9, 2019

Choose a reason for hiding this comment

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

You've written almost exactly the same code here twice, to get the first number and the second number. Could you DRY that up by putting this logic in a method and/or a loop?

# handle divide when attempting to divide by zero (just exit the program).
# make your program know when it needs to return an integer versus a float.

if option == "add" || option == "+"

Choose a reason for hiding this comment

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

Consider using a case/when block to simplify your code.


print "Please input the FIRST number: "
num1 = gets.chomp
while (num1.to_i.to_s != num1.strip)

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 check for valid user input


operations = ["add", "+", "subtract", "-", "multiply", "*", "divide", "/"]

print "\nPlease choose one operator (name or symbol): "

Choose a reason for hiding this comment

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

Using while and include? is a great way to check for valid user input.

@beccaelenzil
Copy link

Calculator

What We're Looking For

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

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