From decb1a18a23367428d10e2e6360e73e36191d4dd Mon Sep 17 00:00:00 2001 From: noahspannbauer Date: Fri, 18 Oct 2024 10:01:50 +0000 Subject: [PATCH] adding bank --- bank/bank.go | 59 +++++++++++++++++++++++++++++++++++++++++ bank/go.mod | 3 +++ profitCalculator/app.go | 25 ++++++++--------- 3 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 bank/bank.go create mode 100644 bank/go.mod diff --git a/bank/bank.go b/bank/bank.go new file mode 100644 index 0000000..e199a26 --- /dev/null +++ b/bank/bank.go @@ -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 + } + } +} \ No newline at end of file diff --git a/bank/go.mod b/bank/go.mod new file mode 100644 index 0000000..401aede --- /dev/null +++ b/bank/go.mod @@ -0,0 +1,3 @@ +module example.com/bank + +go 1.23.1 diff --git a/profitCalculator/app.go b/profitCalculator/app.go index 73b8cd7..6c0583c 100644 --- a/profitCalculator/app.go +++ b/profitCalculator/app.go @@ -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 {