-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrubyatm.rb
49 lines (42 loc) · 1.27 KB
/
rubyatm.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
40
41
42
43
44
45
46
47
def atm_action(balance, action)
case action
when '1' # withdrawal
puts "please enter the amount you wish to withdraw:"
amount = gets.chomp.to_f
if balance - amount < 0
puts "sorry, you don't have that much cash!"
else
balance = balance - amount
end
when '2' # deposit
puts "please enter the amount you wish to deposit:"
amount = gets.chomp.to_f
balance = balance + amount
when '3' # show me my balance
puts "Your balance is: $ #{balance}"
puts "Your balance is: $ " + balance.to_s
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
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
balance = 100.25
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