Skip to content

Conversation

The-Beez-Kneez
Copy link

02/07/2018: Almost finished with the calculator assignment for Week 1

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? I prompted the user to enter their input and stored it in assigned variables.
How did you determine what operation to perform? The user is prompted to input what command they wish to use. I designed methods to allow the user to use: add, multiply, subtract, divide, exponents, and modulos. Within these methods, I accounted for the written command and the operators associated with the commands. So if a user wanted to add, they could input either "add" or "+". I used a loop to restrict their inputs to only these operators.
Do you feel like you used consistent indentation throughout your code? I felt like I did use consistent indentation throughout the assignment. I utilized the command + i add on to auto-indent my code, and made sure to go through multiple times to re-indent.
If you had more time, what would you have added to or changed about the program? I would have liked to account for the last optional that asked that we account for parenthetical preference.

02/07/2018: Almost finished with the calculator assignment for Week 1
02/07/18: Finished and submitting Calculator Assignment for Week 1.
@droberts-sea
Copy link

Calculator

What We're Looking For

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

Great job overall! I have a couple of inline comments below that you should check out, but in general I am quite happy with this submission. Keep up the hard work!

#OPTIONAL: ENSURE IT IS ONLY NUMBERS THAT ARE ENTERED
def req ()
num = gets.chomp
until num =~ /^[1-9]\d*(\.\d+)?$/

Choose a reason for hiding this comment

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

Good use of a regex here to verify user input - way to go above and beyond.

One comment: I'm not so sure about the method name req. This doesn't really tell me what the method does, which will make code that calls it harder to read. I would prefer something more descriptive like read_number.

command_use = gets.chomp
until ["add", "+", "subtract", "-","multiply", "*", "divide", "/", "**", "^", "modulo", "%"].include?(command_use)
puts "Please put a valid command!"
command_use = gets.chomp

Choose a reason for hiding this comment

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

It might be good to let the user know what commands are valid.

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