Advertisement
Guest User

Untitled

a guest
Jun 17th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.63 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "os"
  6.     "strconv"
  7.     "strings"
  8. )
  9.  
  10. func main() {
  11.     coinValue := [4]int{25, 10, 5, 1}
  12.     coins := [4]int{0, 0, 0, 0}
  13.  
  14.     var amount string
  15.  
  16.     r := strings.NewReplacer("$", "", ".", "")
  17.  
  18.     fmt.Scanf("%s", &amount)
  19.  
  20.     result := r.Replace(amount)
  21.  
  22.     convAmount, err := strconv.Atoi(result)
  23.  
  24.     if err != nil {
  25.         fmt.Println(err)
  26.         os.Exit(1)
  27.     }
  28.  
  29.     for i := 0; i < len(coinValue); i++ {
  30.         num := convAmount / coinValue[i]
  31.         coins[i] = num
  32.         convAmount = convAmount % coinValue[i]
  33.     }
  34.  
  35.     fmt.Println(coins[0], "Quarter(s),", coins[1], "Dime(s),", coins[2], "Nickel(s),", coins[3], "Penn(y/ies)")
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement