Created
September 13, 2018 11:41
-
-
Save micahlt/c518fdb79b2d3d346d72468dd8baac95 to your computer and use it in GitHub Desktop.
0.7.4 created by micahlt - https://repl.it/@micahlt/074
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
| # # Welcome message | |
| puts "Hello! Welcome to TextCalc 0.7" | |
| # Define calculator function | |
| def runcalc | |
| # Ask for operator | |
| puts "Add, subtract, divide, multiply, or grow exponentially?" | |
| opor= gets.chomp | |
| if opor == "add" then | |
| # Adding | |
| puts "1st Number" | |
| frst= gets.to_i | |
| puts "2nd Number" | |
| scnd= gets.to_i | |
| puts "Calculating..." | |
| puts frst + scnd | |
| puts "Thank you for using the calc. Type /stop to end the calculator or /again to run it again." | |
| elsif opor == "subtract" | |
| # Subtracting | |
| puts "1st Number" | |
| frst= gets.to_i | |
| puts "2nd Number" | |
| scnd= gets.to_i | |
| puts "Calculating..." | |
| puts frst - scnd | |
| puts "Thank you for using the calc. Type /stop to end the calculator or /again to run it again." | |
| elsif opor == "multiply" | |
| # Multiplying | |
| puts "1st Number" | |
| frst= gets.to_i | |
| puts "2nd Number" | |
| scnd= gets.to_i | |
| puts "Calculating..." | |
| puts frst * scnd | |
| puts "Thank you for using the calc. Type /stop to end the calculator or /again to run it again." | |
| elsif opor == "divide" | |
| # Dividing | |
| puts "1st Number" | |
| frst= gets.to_i | |
| puts "2nd Number" | |
| scnd= gets.to_i | |
| puts "Calculating..." | |
| puts frst / scnd | |
| puts "Thank you for using the calc. Type /stop to end the calculator or /again to run it again." | |
| elsif opor == "grow" or "grow exponentially" | |
| # Exponents | |
| puts "Starting Number" | |
| frst= gets.to_i | |
| puts "Number to multiply by" | |
| scnd= gets.to_i | |
| puts "Calculating..." | |
| puts frst ** scnd | |
| puts "Thank you for using the calc. Type /stop to end the calculator or /again to run it again." | |
| end # Ends the if block | |
| strp= gets.chomp | |
| if strp=="/stop" then puts "Stopped." | |
| elsif strp == "/again" then runcalc | |
| end | |
| end | |
| runcalc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment