-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: master
Are you sure you want to change the base?
Conversation
I addressed all but the last 2 optional enhancements.
CalculatorWhat We're Looking For
|
|
||
operation = gets.chomp.downcase | ||
|
||
if operation == "add" || operation == "+" || operation == "subtract" || operation == "-" || operation == "multiply" || operation == "x" || operation == "*" || operation == "divide" || operation == "/" || operation == "modulo" || operation == "%" |
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
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)
Great code, great use of loops to get valid input |
I addressed all but the last 2 optional enhancements.
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions
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).