Created
April 21, 2020 13:19
-
-
Save draveness/f2055f9c03f587fe42c4a45321c84512 to your computer and use it in GitHub Desktop.
Deposit and Withdraw with float64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
var balance float64 = 0 | |
func main() { | |
deposit(.1) | |
deposit(.2) | |
if balance, ok := withdraw(0.30000000000000004); ok { | |
fmt.Println(balance) | |
} | |
} | |
func deposit(v float64) { | |
balance += v | |
} | |
func withdraw(v float64) (float64, bool) { | |
if v <= balance { | |
balance -= v | |
return v, true | |
} | |
return 0, false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment