Bank account operations

Report a typo

Erick has created a Go program that is a simple banking system. It displays a menu that allows you to perform various operations: deposit/withdraw money, display the account balance or exit the program.

Erick has already created the BankAccount struct and written the code to display the program menu and ask for input. Your task is to create three methods to perform the following operations:

Deposit() — To deposit money into the bank account, it should add the amount to the Balance and then print the following message:

Deposited 100.00, your new balance is: 100.00

Withdraw() — To withdraw money from the bank account, it should subtract the amount from the Balance and then print the following message:

Withdrew 100.00, your new balance is: 0.00

Note that for the Withdraw() method if b.Balance-amount < 0 your program should print the message: "Not enough funds in your bank account, funds:" followed by the current b.Balance and then return.

DisplayBalance() — To print the current bank account Balance. It should print the following message and the balance with two decimal points:

Your current balance is: 100.00

Sample Input 1:

deposit 100.00
balance
exit

Sample Output 1:

Welcome to the bank! Enter the operation you want to perform:
deposit | withdraw | balance | exit
Deposited 100.00, your new balance is: 100.00

Welcome to the bank! Enter the operation you want to perform:
deposit | withdraw | balance | exit
Your current balance is: 100.00

Welcome to the bank! Enter the operation you want to perform:
deposit | withdraw | balance | exit
Exiting...
Write a program in Go
package main

import "fmt"

type BankAccount struct {
Balance float64
}

// Create the Deposit(), Withdraw() and DisplayBalance() methods below:
func (? ?) Deposit(amount float64) {
? += ?
fmt.Printf("Deposited %.2f, your new balance is: %.2f\n", amount, b.Balance)
}

func (? ?) Withdraw(amount float64) {
if ? < ? {
fmt.Printf("Not enough funds in your bank account, funds: %.2f\n", ?)
return
}
? -= ?
fmt.Printf("Withdrew %.2f, your new balance is: %.2f\n", ?, ?)
}

func (? ?) DisplayBalance() {
fmt.Printf("Your current balance is: %.2f\n\n", b.Balance)
}

// DO NOT delete or modify the contents of the main() function!
func main() {
var acc BankAccount
for {
displayMenu()
var amount float64
var choice string
fmt.Scanln(&choice, &amount)

___

Create a free account to access the full topic