adding bank

This commit is contained in:
2024-10-18 10:01:50 +00:00
parent 0d716f8255
commit decb1a18a2
3 changed files with 73 additions and 14 deletions

59
bank/bank.go Normal file
View 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
View File

@@ -0,0 +1,3 @@
module example.com/bank
go 1.23.1

View File

@@ -3,26 +3,23 @@ package main
import "fmt"
func main() {
var revenue float64
var expenses float64
var taxRate float64
revenue := getUserInput("Revenue: ")
expenses := getUserInput("Expenses: ")
taxRate := getUserInput("Tax Rate: ")
fmt.Print("Revenue: ")
fmt.Scan(&revenue)
ebt, profit, ratio := calculateFinancials(revenue, expenses, taxRate)
fmt.Print("Expenses: ")
fmt.Scan(&expenses)
fmt.Print("Tax Rate: ")
fmt.Scan(&taxRate)
fmt.Printf("%.1f\n", ebt)
fmt.Printf("%.1f\n", profit)
fmt.Printf("%.3f", ratio)
}
func calculateFinancials(revenue, expenses, taxRate float64) (float64, float64, float64) {
ebt := revenue - expenses
profit := ebt * (1 - taxRate/100)
ratio := ebt / profit
fmt.Println(ebt)
fmt.Println(profit)
fmt.Println(ratio)
return ebt, profit, ratio
}
func getUserInput(infoText string) float64 {