8000 Naheed - Calculator - Edges by arangn · Pull Request #32 · Ada-C10/calculator · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Naheed - Calculator - Edges #32

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

arangn
Copy link
@arangn arangn commented Aug 8, 2018

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? I stored user input in my program by assigning them names (would they then be called objects?), then recalling them throughout the code
How did you determine what operation to perform? To determine the operations I created a series of "if" statements to check what the user chose
Do you feel like you used consistent indentation throughout your code? Yes I did, and using cmd + I helped too
If you had more time, what would you have added to or changed about the program? I would have liked to use methods to make the code more complete and streamlined, and the way I implemented checking whether the user input is an integer does not consistently work, so I'd like to work on that as well

@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. see inline

You didn't use methods at all in this implementation. The code works the way it's supposed to, but working with methods is one of the core learning goals of this assignment, and I'm worried that you missed this opportunity to practice them. As you work on the data transformation worksheet and RideShare, please make sure you're wrapping each piece of work in its own method.

Other than that, this submission looks good. There are a few places where things could be cleaned up that I've tried to outline below, but in general I'm happy with the code you've written. Keep up the hard work!

#gets numbers from user
puts "First number:"
first_number = gets.chomp.to_f
puts "Second number:"

Choose a reason for hiding this comment

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

Watch your indentation. I don't think these lines should be indented at all.


#checking if number is integer by dividing it by itself
if first_number / first_number == 1 && second_number / second_number == 1

Choose a reason for hiding this comment

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

This is a creative way to address this problem. Unfortunately it's got one big issue: it doesn't work for 0!

puts "#{first_number} * #{second_number} = #{first_number * second_number}"
elsif chosen_operator == "divide" || chosen_operator == "/"
puts "#{first_number} / #{second_number} = #{first_number / second_number}"
end

Choose a reason for hiding this comment

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

You should have an else clause here so that when the user inputs an invalid operator, you can give them a helpful message about what went wrong. As is your program fails silently.


#gets numbers from user
puts "First number:"
first_number = gets.chomp.to_f
Copy link
< 8000 img src="https://avatars.githubusercontent.com/u/21064499?s=48&v=4" alt="@droberts-sea" size="24" height="24" width="24" data-view-component="true" class="avatar circle d-inline-block mr-2" /> droberts-sea Aug 10, 2018

Choose a reason for hiding this comment

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

You've written almost exactly the same code twice to get the two numbers from the user. As is it's only two lines, so it's not so bad, but it makes it difficult to expand that logic. For example, you might want to run this code in a loop until the user enters a valid number. Doing this in a method would mean you only have to write that code once.

if chosen_operator == "add" || chosen_operator == "+"
puts "#{first_number} + #{second_number} = #{first_number + second_number}"
elsif chosen_operator == "subtract" || chosen_operator == "-"
puts "#{first_number} - #{second_number} = #{first_number - second_number}"

Choose a reason for hiding this comment

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

This code isn't repeated, but I think it would still increase readability to wrap this if/elsif section in a method. That would clearly delineate where it starts and ends, and make it explicit what data it needs to work. The method signature might be something like perform_calculation(chosen_operator, first_number, second_number).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
0