-
Notifications
You must be signed in to change notification settings - Fork 44
calculator #40
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
base: master
Are you sure you want to change the base?
calculator #40
Conversation
CalculatorWhat We're Looking For
|
|
||
# Program for calculator. | ||
puts " Welcome to the calculator " | ||
operators_array = %w[add + subtract - divide / multiply * % ^] |
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.
nice
|
||
# To know when it needs to return an _integer_ versus a _float_. | ||
def convert_i_f(value) | ||
if (value =~ /\./) |
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.
This checks to see it if has ANY decimals in it. So the user could enter two of them, more detection of an invalid value would be better.
For example 3...1 is accepted
while flag | ||
puts "Enter the first number " | ||
num1 = gets.chomp | ||
if (num1 =~ /[a-zA-Z]/) |
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.
This only checks for letters (a-z), not punctuation for example.
# To check whether the user input is numeric for second number | ||
flag = true | ||
flag = true | ||
while flag |
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.
notice how this section is a repeat of above... great candidate for a method!
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions