Advertisement
Spocoman

05. Account Balance

Sep 22nd, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.48 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strconv"
  6. )
  7.  
  8. func main() {
  9.     var input string
  10.     fmt.Scanln(&input)
  11.    
  12.     var sum = 0.0
  13.  
  14.     for i:= 0; input != "NoMoreMoney"; i++ {
  15.         money,_ := strconv.ParseFloat(input, 64)
  16.         if money < 0 {
  17.             fmt.Println("Invalid operation!")
  18.             break
  19.         }
  20.         sum += money
  21.         fmt.Printf("Increase: %.2f\n", money)
  22.         fmt.Scanln(&input)
  23.     }
  24.  
  25.     fmt.Printf("Total: %.2f\n", sum)
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement