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

carets Julia Meier calculator #23

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

Conversation

julmeier
Copy link

@julmeier julmeier commented Aug 11, 2017

I addressed all but the last 2 optional enhancements.

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program. Data is stored in variables because there were only three values that needed storage: the operand, the first number and the second number.
How did you determine what operation to perform? I created a method for each of the six operations: +, -, *, /, **, and %. The program receives an operation from the user, and calls the appropriate method ( lines 97 to 116).
How did you make sure your program behaved correctly? I tested the program many times to make sure it was behaving correctly. When I first created the program, and when I later ran into issues, I would create "puts" statements within loops or sections to double check that the program was behaving as I planned. Once it was debugged, I deleted out these puts statements. To create the method "valid_numeric_input" (lines 28-38), I first created the method in a separate ruby file, and tested it there, before copying it into the calculator.
Do you feel like you used consistent indentation throughout your code. I believe I did, but I could use some guidance on how to improve it to meet industry standards.
If you had more time, what would you have added to or changed about the program? If I had time, I would have addressed the last two option enhancements:

1. To address the enhancement that accepts and evaluates one parenthetical statement, I would likely add another block to the "valid_numeric_input" method. This block would check to see if the first and last character entered by the user using the slice method (ex. first_number.slice[-1]), and if true, delete out those characters and evaluate the inside expression. If I wanted to account for the user entering a nested expression (ex. ((3+4) * 5)), my instinct is to first use an array to store the characters in the expression as a separate elements in an array. The array would then identify the number of open and closed bracket sets in total and save that number of sets as a variable. If the number of open brackets was not equal to the number of closed brackets, it would reject the user input. If there were only complete sets, then it would loop through the array (number_of_sets.times) and identify the inner most set of brackets by finding the last "(" and the first ")". It would then evaluate the expression inside the parentheses, and replace the array elements of the expression, including the parentheses, with the resulting answer (7) in the array. It would then continue the times loop.

2. The other optional enhancement is to have the program explicitly return an integer or float. My logic goes that if both inputs are integers or floats with only 1 decimal followed by zero(s), then we know that the resulting answer can be presented as an integer. I would create another method that evaluates the user inputs AND the resulting answer (example: an addition calculation that has the inputs and answer "5.0", "9", "14.0"). The method would evaluate if the answer contains a decimal, and if the decimal is only followed by zeros. If this is true, then it would evaluate each inputs to see if it contains no decimals or a single decimal followed by zero(s).

I addressed all but the last 2 optional enhancements.
@julmeier julmeier closed this Aug 11, 2017
@julmeier julmeier reopened this Aug 11, 2017
@tildeee
Copy link

tildeee commented Aug 14, 2017

Calculator

What We're Looking For

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


operation = gets.chomp.downcase

if operation == "add" || operation == "+" || operation == "subtract" || operation == "-" || operation == "multiply" || operation == "x" || operation == "*" || operation == "divide" || operation == "/" || operation == "modulo" || operation == "%"
Copy link

Choose a reason for hiding this comment

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

doesn't include exponent or **! Which was an optional requirement, not a big deal, but your intro says that it accepts those operators

puts "#{first_number} / #{second_number} = #{answer}"
elsif operation == "modulo" || operation == "%"
answer = modulo(first_number, second_number)
puts "#{first_number} / #{second_number} = #{answer}"
Copy link

Choose a reason for hiding this comment

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

Not a big deal, but you're printing here the equation for a division instead of modulo ;) (same with line 112)

@tildeee
Copy link

tildeee commented Aug 14, 2017

Great code, great use of loops to get valid input

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