I'm new to programming and I'm trying to create a basic finance tracking terminal application. I am trying to get the method to run that is in another script when I make a menu selection. It brings me to the options "Add Income" and "Deduct Expenses" when I select "Make changes to your balance" but when I select "Add Income" or "Deduct Expenses" it does not execute the either method. It worked before but not entirely as intended, I've made minor changes and now it has stopped working and it's got me lost.
What is it that I am doing wrong and how can I do this better?
index.rb
require "tty-prompt"
require_relative ("./income_and_expenses.rb")
$prompt = TTY::Prompt.new
selection = ""
puts "Welcome to FinView, a terminal application that helps you track your finances.
With the help of FinView you are able to document your income and expenses."
def main_menu
return $prompt.select("What would you like to do?",
["Make changes to your balance",
"View current balance",
"View breakdown of income and expenses",
"Create or delete a category",
"Exit"])
end
income_expense_selection = ""
def income_and_expenses_menu
return $prompt.select("What would you like to do?",
["Add Income",
"Deduct Expenses",
"Return to Main Menu"])
end
while selection != "Exit"
selection = main_menu
system "clear"
case selection
when "Make changes to your balance"
income_and_expenses_menu
when "View current balance"
puts "balance"
when "View breakdown of income and expenses"
puts "breakdown"
when "Create or delete a category"
puts "category"
when "Exit"
exit
end
end
while income_expense_selection != "Return to Main Menu"
income_expense_selection = income_and_expenses_menu
system "clear"
case income_expense_selection
when "Add Income"
income
when "Deduct Expenses"
expenses
when "Return to Main Menu"
main_menu
end
end
The 2nd script I am trying to access is
income_and_expenses.rb
def expenses
categories_hash = {
:Bills => 0,
:Utilities => 0,
:Groceries => 0
}
puts "Type in the category you would like add expenses to"
puts categories_hash.keys
chosen_category = gets.chomp.capitalize
if chosen_category == "Bills"
puts "What amount?"
expense_amount = gets.chomp.to_i
categories_hash = expense_amount
end
puts "Your expenses for #{:Bills} has included the amount of #{expense_amount}"
end
def income
puts "Please enter your income"
balance = gets.chomp.to_i
puts "Your added income is #{balance}"
end