Exit The Program
Part of the Fundamentals section of Coddy's Ruby journey — lesson 80 of 88.
Challenge
EasyCreate the basic structure for the Daily Expense Tracker. Your program should:
- Initialize an empty array called
expenses - Create a
loop dothat displays the menu and reads user input - When the user enters
"5", printGoodbye!and exit the loop
The menu should display exactly as follows (note the blank line before the title):
--- Expense Tracker ---
1. Add Expense
2. View Expenses
3. Total & Average
4. Clear All
5. Exit
Choose an option: Use puts for the menu lines and print for the "Choose an option: " prompt (so the cursor stays on the same line).
The program will receive one input representing the user's menu choice. For this challenge, the input will always be "5" to test the exit functionality.
When the user enters "5", the output should be:
--- Expense Tracker ---
1. Add Expense
2. View Expenses
3. Total & Average
4. Clear All
5. Exit
Choose an option: Goodbye!Try it yourself
# TODO: Write your code below
# Use puts to print each line of the menu
puts "--- Expense Tracker ---"
puts "1. Add Expense"
puts "2. View Expenses"
puts "3. Total & Average"
puts "4. Clear All"
puts "5. Exit"All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 42Variables and Data Types
Numbers and VariablesString Data TypeBoolean Data TypeSymbol Data TypeChecking Data TypesNaming ConventionsRecap - Variable Creation8Loops
For Loop with RangesWhile LoopBreakNextRecap - FactorialTimes LoopUntil LoopNested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators6Basic IO
Output with putsOutput with print and pOutput With VariablesInput with getsChomp MethodType ConversionRecap - Age CalculatorRecap - True or False9Methods
Defining a MethodMethod ParametersReturn ValuesRecap - Sigma MethodRecap - Validation MethodDefault Parameter Values15Daily Expense Tracker
Project OverviewExit The Program