Forked from cyrusthecool/gist:51f053667e5a5a8aa0bf9e15d2b9062e
Last active
July 2, 2018 10:13
-
-
Save zailleh/e1fa70ed77b26beb1a18cda60c452a67 to your computer and use it in GitHub Desktop.
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
def addition_function # declare this outside of the case and loop so we can call it repeatedly | |
puts "Which numbers would you like to add?" | |
n1 = gets.chomp.to_i | |
n2 = gets.chomp.to_i | |
answer = n1 + n2 | |
puts "The sum is: #{answer}" | |
end | |
def show_menu | |
puts "Calculator" | |
puts"-" * 40 | |
puts "[a] - Addition" | |
puts "[m] - Multiplication" | |
puts "[s] - Subtraction" | |
puts "[d] - Division" | |
puts "[r] - Square Root" | |
puts "[e] - Exponent" | |
puts "[f] - Finance Calculation" | |
puts "[t] - Trip Calculation" | |
puts "[q] - Quit" | |
puts"-" * 40 | |
print "Enter your selection:" | |
end | |
show_menu | |
menu_choice = gets.chomp.downcase | |
until menu_choice == 'q' | |
case menu_choice | |
when'a' | |
addition_function | |
end | |
show_menu #this will run now after the cae statement has run, thereby returnning to the menu when the addition is complete | |
menu_choice = gets.chomp.downcase # ask for the menu_choice again so our choice can change between loops | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment