Skip to content

Conversation

brittanyrjones
Copy link

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? I stored the user input by using the gets.chomp method, and then setting the user input to a variable.
How did you determine what operation to perform? I determined what operation to use by using a case loop with an if conditional nested inside to account for division by zero.
Do you feel like you used consistent indentation throughout your code? I feel like there were some sections of my code that were indented correctly, but there were a few places that the codes started to create the triangle, and make things a little messy.
If you had more time, what would you have added to or changed about the program? If I had more time, I would have indented my conditionals better. I may have even used a method to reduce the triangles that happened on variable a and b. I also would have not used as many methods, because when I realized there was a bug and I tried to fix it, it was somewhere in one of the methods. I had a hard time figuring out how to fix it and change the rest of the code, since some of my operations later in the code depended on the methods that I called previously, which had some errors.

@CheezItMan
Copy link

Calculator

What We're Looking For

Feature Feedback
Takes in two numbers and an operator and performs the mathematical operation. It doesn't work with *
Baseline
Readable code with consistent indentation. In some places you indented too much. You should, in general indent by one tab, or two spaces (pick one and be consistent).
Extras
Summary You hit all the requirements, good and had nice ways to trap user input and force them to enter a number, nice! One thing to look at is that there is no way to force them to enter a valid operator. BTW case is not a loop. It's a special kind of conditional. Also Ruby files should end with .rb instead of .md. The dot-something at the end of a filename lets us and the Mac know what kind of file it is. .md is for Markdown, and .rb is for Ruby.

puts "\nEnter the the first number:"
a = gets.chomp
while true
if a.to_f.to_s == a || a.to_i.to_s == a

Choose a reason for hiding this comment

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

Works great, but I'd encourage you to make a loop that repeats while the input is wrong and not infinitely and then break out when the input is valid. It just makes reading the code flow a little harder.

Also a doesn't make a good variable name. The name doesn't tell anyone what the variable would be used for.

Lastly you also indented too much here. Indent by 1 tab or 2 spaces and be consistent.

end
##### NOT SURE IF THIS SECTION IS NEEDED AT ALL, ESPECIALLY IF I HAVE CONVERTED THE USER INPUT INTO FLOAT/Integer.#####
# change data types of number to float to account for decimal numbers.
def num_class(i)

Choose a reason for hiding this comment

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

If you want to avoid showing a decimal for integer math, then it's necessary.


# Get another number from the user.
puts "Give me another number:"
b = gets.chomp

Choose a reason for hiding this comment

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

More cryptic variable names noooooooo!!!

a = num_class(a)
b = num_class(b)
#### End of unworthy code which depend upon the previously written uworthy code####
# Case Loop

Choose a reason for hiding this comment

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

A case is not a loop, but a conditional like an if statement.

else puts "Please enter a number other than '0' when using division"
end
#Add support for the modulo operator (10 % 3 = 1).
when '%' , 'modulo'

Choose a reason for hiding this comment

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

nice

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