-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathatm.go
102 lines (79 loc) · 2.37 KB
/
atm.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"fmt"
"github.com/engichang1467/ATM-Simulator-Go/clear"
)
var balance float32 = 0
var anotherTransaction int
func transaction() {
var choice int
fmt.Printf("\nEnter any option to be served!\n\n")
fmt.Printf("1. Withdraw\n")
fmt.Printf("2. Deposit\n")
fmt.Printf("3. Balance\n\n")
fmt.Scan(&choice)
// fmt.Print(choice)
var amountToWithDraw float32
var amountToDeposit float32
switch choice {
case 1:
// Withdraw
fmt.Printf("\nPlease enter amount to withdraw: ")
fmt.Scan(&amountToWithDraw)
if amountToWithDraw > balance {
fmt.Printf("There is no insufficient funds in your account")
fmt.Printf("Do you want another transaction?\nPress 1 to proceed and 2 to exit\n\n")
fmt.Scan(&anotherTransaction)
switch anotherTransaction {
case 1:
clear.CallClear()
transaction()
default:
fmt.Println("\nThanks for using our service!!! \nHave a nice day")
}
} else {
balance -= amountToWithDraw
fmt.Printf("You have withdrawn $%.2f and your new balance is $%.2f ", amountToWithDraw, balance)
fmt.Printf("\n\nDo you want another transaction?\nPress 1 to proceed and 2 to exit\n\n")
fmt.Scan(&anotherTransaction)
switch anotherTransaction {
case 1:
clear.CallClear()
transaction()
default:
fmt.Println("\nThanks for using our service!!! \nHave a nice day")
}
}
case 2:
// Deposit
fmt.Printf("\nPlease enter amount to deposit: ")
fmt.Scan(&amountToDeposit)
balance += amountToDeposit
fmt.Printf("Thank you for depositing, new balance is: $%.2f", balance)
fmt.Printf("\n\nDo you want another transaction?\nPress 1 to proceed and 2 to exit\n\n")
fmt.Scan(&anotherTransaction)
switch anotherTransaction {
case 1:
clear.CallClear()
transaction()
default:
fmt.Println("\nThanks for using our service!!! \nHave a nice day")
}
case 3:
fmt.Printf("\nYour bank balance is: $%.2f", balance)
fmt.Printf("\n\nDo you want another transaction?\nPress 1 to proceed and 2 to exit\n\n")
fmt.Scan(&anotherTransaction)
switch anotherTransaction {
case 1:
clear.CallClear()
transaction()
default:
fmt.Println("\nThanks for using our service!!! \nHave a nice day")
}
}
}
func main() {
// fmt.Println("It is working")
fmt.Printf("\nWelcome to my ATM Simulator\n")
transaction()
}