Conversation
CalculatorWhat We're Looking For
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! |
calculator.rb
Outdated
| num2 = gets.chomp.to_f | ||
| end | ||
| answer = num1 / num2 | ||
| else |
calculator.rb
Outdated
| while num2 <= 0 | ||
| puts "please enter a different number for your 2nd number, as it has to be greater than 0" | ||
| num2 = gets.chomp.to_f | ||
| end |
There was a problem hiding this comment.
Dividing by something less than 0 is fine, it's only dividing by 0 itself that is a problem.
calculator.rb
Outdated
| else | ||
| puts "please only pick from following operators\n 1. add(+)\n 2. subtract(-)\n 3. multiply(*)\n 4. divide(/)" | ||
| operator = gets.chomp | ||
| end |
There was a problem hiding this comment.
Here you ask the user for another operator, but you don't use that information. The if statement ends, and you ask whether the user wants to play again, and then they need to choose another operator.
calculator.rb
Outdated
| puts "pick 1st number" | ||
| num1 = gets.chomp.to_f | ||
|
|
||
| puts "pick 2nd number" |
There was a problem hiding this comment.
This code to pick two numbers is repeated many times. Could you DRY this up? You could either write a method, or move the number picking outside the if statement.
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions