+ 2

Out of 5 , 2 cases are getting wrong. Help me out

You are working on a banking app. The code declares a BankAccount struct with a balance field. You need to add a withdraw() method for the BankAccount struct. It should take an integer argument and decrease the balance of the Bank Account by the given amount. In case there is not enough money in the account, the method should output "Insufficient Funds". package main import "fmt" type BankAccount struct { holder string balance int } func (ptr *BankAccount) withdraw(amount int){ ptr.balance-= amount } func main() { acc := BankAccount{"James Smith", 100000} var amount int var balance int fmt.Scanln(&amount) acc.withdraw(amount) fmt.Println(acc) if(amount<balance){ fmt.Println("Insufficient Funds") } acc.withdraw(amount) }

28th Jul 2021, 6:45 PM
Chinmay Anand
Chinmay Anand - avatar
5 Answers
+ 1
NotAPythonNinja it's not working
29th Jul 2021, 8:27 AM
Chinmay Anand
Chinmay Anand - avatar
+ 1
package main import "fmt" type BankAccount struct {   holder string   balance int } func (ptr *BankAccount) withdraw(amount int){         if(amount<ptr.balance){        ptr.balance-= amount        fmt.Println(ptr.balance)    } else{       fmt.Println("Insufficient FundS")}     } func main() {   acc := BankAccount{"James Smith", 100000}       var amount int     fmt.Scanln(&amount)     acc.withdraw(amount)   fmt.Println(acc)     acc.withdraw(amount)     } David Ordås please check once. Out of 5 cases I am getting two wrong.
29th Jul 2021, 8:43 AM
Chinmay Anand
Chinmay Anand - avatar
29th Jul 2021, 9:31 AM
David OrdĂĄs
David OrdĂĄs - avatar
+ 1
package main import "fmt" type BankAccount struct { holder string balance int } func (acc *BankAccount) withdraw(amount int) { if amount <= 100000 { acc.balance -= amount } else { fmt.Println("Insufficient Funds") } } func main() { acc := BankAccount{"James Smith", 100000} var amount int fmt.Scanln(&amount) acc.withdraw(amount) fmt.Println(acc) }
21st Apr 2023, 1:41 PM
Esa Krissa
Esa Krissa - avatar
29th Jul 2021, 6:44 AM
Chinmay Anand
Chinmay Anand - avatar