-
Notifications
You must be signed in to change notification settings - Fork 49
Space - Jeta #48
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?
Space - Jeta #48
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||||
| #Add,Subtract,Multiply,Divide Methode | ||||||
| def operation(num_one, math_operation, num_two) | ||||||
| if math_operation == "Add" || math_operation == "+" | ||||||
| result = ((num_one.to_f) + (num_two.to_f)).round(2) | ||||||
| elsif math_operation == "Subtract" || math_operation == "-" | ||||||
| result = ((num_one.to_f) - (num_two.to_f)).round(2) | ||||||
| elsif math_operation == "Multiply" || math_operation == "*" | ||||||
| result = ((num_one.to_f) * (num_two.to_f)).round(2) | ||||||
| elsif math_operation == "Divide" || math_operation == "/" | ||||||
| result = ((num_one.to_f) / (num_two.to_f)).round(2) | ||||||
| end | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation
Suggested change
|
||||||
| return result | ||||||
| end | ||||||
|
|
||||||
| #Validate if input is an math operator | ||||||
| def ValidOperator (math_operation) | ||||||
| until ["Add","+", "Subtract","-", "Multiply", "*", "Divide", "/"].include? math_operation | ||||||
| puts "Enter a valid selection" | ||||||
| math_operation = gets.chomp | ||||||
| end | ||||||
| return math_operation | ||||||
| end | ||||||
|
Comment on lines
+16
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation issues here. |
||||||
|
|
||||||
| #Validate if the input is Number | ||||||
| def ValidNumber (number) | ||||||
| until (Integer(number) rescue nil) !=nil || (Float(number) rescue nil) !=nil #Returns nil if it is not integer or Float else returns number | ||||||
| puts "Enter a valid number" | ||||||
| number = gets.chomp.to_i | ||||||
| end | ||||||
|
Comment on lines
+27
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More messy indentation. |
||||||
| return number.to_i | ||||||
| end | ||||||
|
|
||||||
| #Program Start | ||||||
| puts "Welcome to the Calcuator Program." | ||||||
|
|
||||||
| operator_array = ["Add(+)", "Subtract(-)", "Multiply(*)", "Divide(/)"] | ||||||
| puts operator_array | ||||||
|
|
||||||
| #Accept operator input | ||||||
| puts"Please enter the operator would you like to use?" | ||||||
| math_operation = gets.chomp | ||||||
| math_operation = ValidOperator(math_operation) | ||||||
|
|
||||||
| #Accept first number | ||||||
| puts "Enter your first number." | ||||||
| num_one = gets.chomp.to_i | ||||||
| num_one = ValidNumber(num_one) | ||||||
|
|
||||||
| #Accept second number | ||||||
| puts "Enter your second number." | ||||||
| num_two = gets.chomp.to_i | ||||||
| num_two = ValidNumber(num_two) | ||||||
|
|
||||||
|
|
||||||
| final_result = operation(num_one, math_operation, num_two) | ||||||
| puts "Result is #{final_result}" | ||||||
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.
I suggest capitalizing
math_operation, before starting these if-elsif comparisons.