Skip to content

Instantly share code, notes, and snippets.

@stupeters187
Created March 30, 2016 20:31
Show Gist options
  • Save stupeters187/71b846fadb99e3526550ee82c481d682 to your computer and use it in GitHub Desktop.
Save stupeters187/71b846fadb99e3526550ee82c481d682 to your computer and use it in GitHub Desktop.
require 'pry'
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
@states[:NV] = 'Nevada'
@states[:UT] = 'Utah'
@cities = Hash.new{}
@cities[:NV] = ['Reno', 'Sparks', 'LV']
@cities[:CA] = ['Sunnyvale', 'Fresno', 'Oakland']
# puts states
# puts cities
def describe_state
puts "Enter state code"
key = gets.chomp.to_sym
puts @cities.fetch(key)
end
@taxes = Hash.new{}
@taxes[:NV] = 7.5
@taxes[:CA] = 10
def calculate_tax()
puts "Enter state code"
state = gets.chomp.to_sym
puts "Enter amount"
amount = gets.chomp.to_f
tax_amount = amount * @taxes.fetch(state) / 100
puts tax_amount.round(2)
end
def find_state_for_city()
puts "Enter city name"
input = gets.chomp.capitalize
@cities.each do |state, cities_array|
if cities_array.include?(input)
puts state
end
end
end
# puts cities.fetch(:NV) {|i| puts i}
# describe_state
# calculate_tax
find_state_for_city
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment