forked from AdaGold/calculator
-
Notifications
You must be signed in to change notification settings - Fork 44
Ampers: Steffany Brown #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
Open
steffnay
wants to merge
3
commits into
Ada-C9:master
Choose a base branch
from
steffnay:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # This is a calculator program | ||
|
|
||
| # Define methods | ||
|
|
||
| def add(num_one, num_two) | ||
| return num_one + num_two | ||
| end | ||
|
|
||
| def subtract(num_one, num_two) | ||
| return num_one - num_two | ||
| end | ||
|
|
||
| def multiply(num_one, num_two) | ||
| return num_one * num_two | ||
| end | ||
|
|
||
| def divide(num_one, num_two) | ||
| return num_one / num_two | ||
| end | ||
|
|
||
| def exponent(num_one, num_two) | ||
| return num_one ** num_two | ||
| end | ||
|
|
||
| possible_operations = ["ADD", "SUBTRACT", "DIVIDE", "MULTIPLY", "EXPONENT", "+", "-","/", "*", "^"] | ||
|
|
||
| # Get user input for the operation to perform | ||
| # Ask for user input until operation is valid | ||
| puts "Which operation would you like to perform?" | ||
| print "(Add, Subtract, Multiply, Divide, Exponent) " | ||
| operation = gets.chomp.upcase | ||
| until possible_operations.include?(operation) | ||
| puts "That is an invalid operation. Try again" | ||
| operation = gets.chomp.upcase | ||
| end | ||
|
|
||
| # Get user input for numbers | ||
| # Ask for input until user enter integer | ||
| puts "Okay, please enter a number." | ||
| num_one = gets.chomp | ||
| while num_one.to_i.to_s != num_one | ||
| puts "That is not a valid number. Please try again." | ||
| num_one = gets.chomp | ||
| 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 is a lil off here too |
||
|
|
||
| num_one = num_one.to_i | ||
|
|
||
|
|
||
| puts "Please enter another number." | ||
| num_two = gets.chomp | ||
|
|
||
| while num_two.to_i.to_s != num_two | ||
| puts "That is not a valid number. Please try again." | ||
| num_two = gets.chomp | ||
| end | ||
|
|
||
| num_two = num_two.to_i | ||
|
|
||
| # Perform calculations | ||
| if operation == "ADD" || operation == "+" | ||
| sum = add(num_one, num_two) | ||
| puts "#{num_one} + #{num_two} = #{sum}" | ||
| return sum | ||
| elsif operation == "SUBTRACT" || operation == "-" | ||
| sum = subtract(num_one, num_two) | ||
| puts "#{num_one} - #{num_two} = #{sum}" | ||
| return sum | ||
| elsif operation == "MULTIPLY" || operation == "*" | ||
| sum = multiply(num_one, num_two) | ||
| puts "#{num_one} * #{num_two} = #{sum}" | ||
| return sum | ||
| elsif operation == "DIVIDE" || operation == "/" | ||
| sum = divide(num_one, num_two) | ||
| puts "#{num_one} / #{num_two} = #{sum}" | ||
| return sum | ||
| elsif operation == "EXPONENT" || operation == "^" | ||
| sum = exponent(num_one, num_two) | ||
| printing_exponent = num_two - 1 | ||
| print "#{num_one}^#{num_two} = " | ||
| print num_one | ||
| printing_exponent.times { print " * #{num_one}"} | ||
| print " = #{sum}\n" | ||
| return sum | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
indentation is a lil off here