-
Notifications
You must be signed in to change notification settings - Fork 1
/
rubyatm_start.rb
39 lines (29 loc) · 896 Bytes
/
rubyatm_start.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def atm_action(balance, action)
case action
when '1' # withdrawal
when '2' # deposit
when '3' # show me my balance
when 'exit' # leave the ATM
puts "Thanks for banking with the Ruby ATM!"
else
puts "Invalid selection, try again!"
end
return balance
end
# code starts executing here, and calls the atm_action method until exit...
puts "Hello! What's your name?"
name = gets.chomp
puts "Welcome to the Ruby ATM. Please enter your initial deposit:"
balance = gets.chomp.to_f
action = ""
while action != 'exit'
puts " "
puts "Please enter your selection:"
puts " * Enter 1 for withdrawals "
puts " * Enter 2 for deposits "
puts " * Enter 3 to check your balance "
puts " * Enter exit to leave the Ruby ATM "
action = gets.chomp.downcase
balance = atm_action(balance, action)
puts "Transaction complete."
end