-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
151 lines (134 loc) Β· 3.02 KB
/
main.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import (
"fmt"
"os"
)
var menuNumber int
var pin = 0000
var accountBalance = 1000.00
func main() {
welcome()
//create a prompt for the user to enter their pin
fmt.Println("Please enter your pin")
//scan the pin
_, err := fmt.Scan(&pin)
if err != nil {
return
}
//check if the pin is correct
if pin == 0000 {
//if the pin is correct, run the main menu
mainMenu()
} else {
//if the pin is incorrect, print an error message
fmt.Println("Error: Incorrect pin")
//run the main function again
main()
//if the user enters the pin incorrectly 3 times, display an error message and exit the program
}
}
func welcome() {
fmt.Println("ππΎππΎππΎππΎ Welcome to Hussain atm CLI app where banking is flawless. ππΎππΎππΎππΎ")
newLine(1)
}
func mainMenu() {
newLine(1)
fmt.Println("Select operation:")
fmt.Println("1. Change pin \t")
fmt.Println("2. Check account balance \t")
fmt.Println("3. Withdraw money \t")
fmt.Println("4. Deposit money")
fmt.Println("0. Cancel/Exit the program")
_, err := fmt.Scan(&menuNumber)
if err != nil {
fmt.Println("Error:, please select the correct menu item")
}
switch menuNumber {
case 1:
changePin()
case 2:
checkAccountBalance()
case 3:
withdrawMoney()
case 4:
DepositMoney()
case 0:
exitProgram()
default:
fmt.Println("Error: Invalid input")
}
}
func changePin() {
newLine(1)
fmt.Println("Please enter your new pin π:")
var newPin int
_, err := fmt.Scan(&newPin)
if err != nil {
fmt.Println("Error: Invalid input β½")
}
pin = newPin
fmt.Println("Pin changed successfully π")
performAnotherOperation()
}
// check account balance
func checkAccountBalance() {
newLine(1)
fmt.Println("Your account balance is: ", accountBalance)
performAnotherOperation()
}
// withdraw money
func withdrawMoney() {
newLine(1)
fmt.Println("Enter the amount you want to withdraw π΅:")
var amount float64
_, err := fmt.Scan(&amount)
if err != nil {
fmt.Println("Error: Invalid input β½")
}
if amount > accountBalance {
fmt.Println("Error: Insufficient funds π₯Ή")
} else {
accountBalance -= amount
fmt.Println("Withdrawal successful π€")
}
performAnotherOperation()
}
// DepositMoney deposit money
func DepositMoney() {
newLine(1)
fmt.Println("Enter the amount you want to deposit:")
var amount float64
_, err := fmt.Scan(&amount)
if err != nil {
fmt.Println("Error: Invalid input")
}
accountBalance += amount
fmt.Println("Deposit successful π€")
performAnotherOperation()
}
func performAnotherOperation() {
fmt.Println("Do you want to perform another operation? (Y/N)")
var answer string
_, err := fmt.Scan(&answer)
if err != nil {
fmt.Println("Error: Invalid input")
}
if answer == "Y" {
mainMenu()
} else if answer == "N" {
exitProgram()
} else {
fmt.Println("Error: Invalid input")
}
}
// exit program
func exitProgram() {
fmt.Println("Thanks for banking with us π€")
os.Exit(0)
}
func newLine(numberOfLines int) {
for i := 0; i < numberOfLines; {
fmt.Println("\n")
i++
}
}