adding bank
This commit is contained in:
59
bank/bank.go
Normal file
59
bank/bank.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var accountBalance = 1000.0
|
||||||
|
|
||||||
|
fmt.Println("Welcome to Go Bank!")
|
||||||
|
|
||||||
|
for {
|
||||||
|
fmt.Println("What do you want to do?")
|
||||||
|
fmt.Println("1. Check balance")
|
||||||
|
fmt.Println("2. Deposit money")
|
||||||
|
fmt.Println("3. Withdraw money")
|
||||||
|
fmt.Println("4. Exit")
|
||||||
|
|
||||||
|
var choice int
|
||||||
|
fmt.Print("Your choice: ")
|
||||||
|
fmt.Scan(&choice)
|
||||||
|
|
||||||
|
switch choice {
|
||||||
|
case 1:
|
||||||
|
fmt.Println("Your balance is: ", accountBalance)
|
||||||
|
case 2:
|
||||||
|
fmt.Print("Your deposit: ")
|
||||||
|
var depositAmount float64
|
||||||
|
fmt.Scan(&depositAmount)
|
||||||
|
|
||||||
|
if depositAmount <= 0 {
|
||||||
|
fmt.Println("Invalid amount. Must be greater than 0.")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
accountBalance += accountBalance
|
||||||
|
fmt.Println("Balance updated! New amount:", accountBalance)
|
||||||
|
case 3:
|
||||||
|
fmt.Print("Your withdrawal")
|
||||||
|
var withdrawalAmount float64
|
||||||
|
fmt.Scan(&withdrawalAmount)
|
||||||
|
|
||||||
|
if withdrawalAmount <= 0 {
|
||||||
|
fmt.Println("Invalid amount. Must be greater than 0.")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if withdrawalAmount > accountBalance {
|
||||||
|
fmt.Println("Invalid amount. You can't withdraw more than you have.")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
accountBalance -= withdrawalAmount
|
||||||
|
fmt.Println("Balance updated! New amount:", accountBalance)
|
||||||
|
default:
|
||||||
|
fmt.Println("Goodbye!")
|
||||||
|
fmt.Println("Thanks for choosing our bank")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
bank/go.mod
Normal file
3
bank/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module example.com/bank
|
||||||
|
|
||||||
|
go 1.23.1
|
||||||
@@ -3,26 +3,23 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var revenue float64
|
revenue := getUserInput("Revenue: ")
|
||||||
var expenses float64
|
expenses := getUserInput("Expenses: ")
|
||||||
var taxRate float64
|
taxRate := getUserInput("Tax Rate: ")
|
||||||
|
|
||||||
fmt.Print("Revenue: ")
|
ebt, profit, ratio := calculateFinancials(revenue, expenses, taxRate)
|
||||||
fmt.Scan(&revenue)
|
|
||||||
|
|
||||||
fmt.Print("Expenses: ")
|
|
||||||
fmt.Scan(&expenses)
|
|
||||||
|
|
||||||
fmt.Print("Tax Rate: ")
|
fmt.Printf("%.1f\n", ebt)
|
||||||
fmt.Scan(&taxRate)
|
fmt.Printf("%.1f\n", profit)
|
||||||
|
fmt.Printf("%.3f", ratio)
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculateFinancials(revenue, expenses, taxRate float64) (float64, float64, float64) {
|
||||||
ebt := revenue - expenses
|
ebt := revenue - expenses
|
||||||
profit := ebt * (1 - taxRate/100)
|
profit := ebt * (1 - taxRate/100)
|
||||||
ratio := ebt / profit
|
ratio := ebt / profit
|
||||||
|
return ebt, profit, ratio
|
||||||
fmt.Println(ebt)
|
|
||||||
fmt.Println(profit)
|
|
||||||
fmt.Println(ratio)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUserInput(infoText string) float64 {
|
func getUserInput(infoText string) float64 {
|
||||||
|
|||||||
Reference in New Issue
Block a user