You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Congratulations! You're submitting your assignment.
Comprehension Questions
Question
Answer
Describe how you stored user input in your program?
Currently, all inputs from user are stored in a simple variable (user_operation, user_number_type, first_number, second_number). In a more advanced version of the program, which accepts more than two numbers and more than one operation, the whole formula will be stored in a string, then converted to relevant information for computation.
How did you determine what operation to perform?
Users are provided a list of all operations supported by the program. Users' choice is collected and used to determine which operation to perform. Case match is used for implementation of computation.
Do you feel like you used consistent indentation throughout your code?
Yes.
If you had more time, what would you have added to or changed about the program?
1. Finish the advanced version of the program, which accepts more than two numbers and more than one operation, including parenthesis if possible. 2. Fix a corner case in the float_check method (a float with last digit as 0, such as 2.10). Right now, if the user enter 2.10, the program treats it as an invalid float number. This is because "2.10".to_f.to_s generates "2.1", and "2.10" != "2.1". This won't affect the functions of the calculator. But because this type of number is meaningful in certain context, such as money value, it's meaningful to allow users to enter such numbers.
Takes in two numbers and an operator and performs the mathematical operation.
x
Readable code with consistent indentation.
x
Overall, great job!
Your user_choice_check method is really robust; I like that you pass in a list of valid choices as an argument. It makes the code very flexible
I think how you handle checking the input if it's a valid integer or float (with the lines integer.to_s == integer_string and float.to_s == float_string) are very clever :)
One last clever thing you did was just puts operations and puts number_types. This way, if you update the arrays operations or number_types, you don't have to update the operations or number types array.
@tildeee Thanks for the comments :) My first thought for input check was to use regex, then I realized it would take me quite a while to figure out how to write regex code correctly. I don't see regex in our syllabus. Are we going to learn about it in the future? If not, do you have any recommendations for me to look at?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions