[Solved] Multiple-value function single-value context - Works with fmt.Println but not with fmt.Printf

Hi Gophers,
I’ve been through the threads that address this issue, but quite frankly was further confused.
I am not a developer, just someone trying to learn golang, so pardon if you see any errors/stupidity.

Here’s what I am trying to do:

        package main

        import "fmt"

        func main() {
        		fmt.Println(addNavg(50, 50)) //This works fine
                fmt.Printf("%f\n", addNavg(50.0, 50.0)) //This does not work
        	fmt.Printf("%f %f\n", addNavg(50.0, 50.0)) //This does not work too


        func addNavg(num1 float64, num2 float64) (float64, float64) {
        	num3 := num1 + num2
        	num4 := (num1 + num2) / 2
        	return num3, num4


If I use fmt.Println it all works fine. But if I use fmt.Printf I get the error:

    ./main.go:10:31: multiple-value addNavg() in single-value context

I read the existing threads and the first one I came across, the OP of that thread had noticed issue with fmt.Println. But I’m getting it for fmt.Printf. Where am I going wrong/being stupid?

1 Like

Just use temp vars

a, b := addNavg(50.0, 50.0)
fmt.Printf("%f %f\n", a, b)

Hi Yamil,
It worked!!. Why my dumb skull didn’t think of this is beyond me. My worst problem is, while I understood the verbiage of the error, I did not know how to fix it. That’s never happened before. I’ve dabbled in Perl and a bit of Python, and was able to fix errors. Hope one day I will get this right. :smiley:

1 Like

jejeje, No problem We all are learning!!!


Yes, just that I am not happy at the speed ( rather the lac of ) my learning speed. I’m learning golang because it produces a single binary. Where I work, the corporate network restrictions are…well…corporal…so I cannot install the modules nor can I install different versions of python on the production servers to get my scripts running there. I’m not trying anything fancy, just ssh’ing into hosts and getting outputs and filtering , emailing them, but cannot install for example paramiko or anything such. No pip install is allowed. :frowning:
That and the fact that I might get an edge on my similar job profile guys (Storage Consultants) with golang on my resume.
I was almost ready to be RTFM’d here, and perhaps “golang is not for you dumbass, get off the lawn”, but thankfully that hasn’t happened (yet) :smiley:


step by step, don’t despair and never give up!!! :smiley:


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.