gointextra

How to fix %!(EXTRA int=3) error in Golang?


I'm quite new to Golang and I'd like to know why this error keeps coming out every time i run the code
%!(EXTRA int=3)

...
var money int
var buyItem string
fmt.Print("Inserisci il nome dell'arma che vuoi comprare: ")
fmt.Scan(&buyItem)
switch buyItem {
        case "Racchetta":
            fmt.Println("Hai comprato con successo la racchetta")
            money = money - 1
            fmt.Printf("Soldi rimanenti:", money)
        case "Granata":
            fmt.Println("Hai comprato con successo la granata")
            money = money - 7
            fmt.Printf("Soldi rimanenti:", money)
        case "AK":
            fmt.Println("Hai comprato con successo l'AK")
            money = money - 12
            fmt.Printf("Soldi rimanenti:", money)
        default:
            fmt.Println("Non hai inserito il nome dell'arma corretto")
}

When I run it,I get this error: Soldi rimanenti:%!(EXTRA int=3) Can anyone help me?


Solution

  • You need to add formatters to your string, e.g.

    fmt.Printf("Soldi rimanenti: %v\n", money)
    

    %v is a general formatter, good for most cases, but more exists. Check out examples here https://gobyexample.com/string-formatting

    \n is for adding line return after the print.