Skip to content

Sammi-Jo's calculator.rb (nodes)#21

Open
sjlee3157 wants to merge 1 commit intoAda-C10:masterfrom
sjlee3157:master
Open

Sammi-Jo's calculator.rb (nodes)#21
sjlee3157 wants to merge 1 commit intoAda-C10:masterfrom
sjlee3157:master

Conversation

@sjlee3157
Copy link

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? As a global variable ($num1 / $num2) that gets passed to different methods that validate, return floats, operate, and print.
How did you determine what operation to perform? With a case conditional that checked the user's request against separate array "thesauruses". These could be refactored into a single array of hashes.
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? See below (pasted from my code).
# To do:
# put arrays in an array of hashes
# do I really need all of the dollar signs?
# parentheticals? refactor without asking 3 times. input expression. remove whitespace. split string by a known operator. string 1 = num1, operator = operator, string 2 = num2.
# square root
# repeat unless type quit to quit

@CheezItMan
Copy link

Calculator

What We're Looking For

Feature Feedback
Takes in two numbers and an operator and performs the mathematical operation. Check
Readable code with consistent indentation. Check
Summary Well done you hit all the learning goals and went beyond with exponents and rounding decimals. I will say again, please avoid using global variables, they're a bad habit to get into. We'll talk about them later in the course.

# calculator.rb
# https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2FAda-C10%2Fcalculator&sa=D&usd=2&usg=AFQjCNF8YsY1ij6pguWOvbMUgTJO86XQ7Q

$known_adds = ["+", "add", "plus"]

Choose a reason for hiding this comment

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

We'll get into this as a class later, but never ever ever use global variables. It's a bad practice and can make code that's very hard to debug.

Copy link
Author

Choose a reason for hiding this comment

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

Haha... well learning about scope and constants today was definitely a game changer for me!

def check_number(label)
print "Number #{label}\t"
number = gets.chomp
allowed_number = /\A-{0,1}\d{0,}(\.\d{0,})?\z/

Choose a reason for hiding this comment

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

Nice use of regex

@sjlee3157 sjlee3157 changed the title Sammi-Jo's calculator.rb Sammi-Jo's calculator.rb (nodes) Aug 15, 2018
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