Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zailleh/e1fa70ed77b26beb1a18cda60c452a67 to your computer and use it in GitHub Desktop.
Save zailleh/e1fa70ed77b26beb1a18cda60c452a67 to your computer and use it in GitHub Desktop.
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