title: go compile errors: undefined variables
body: <p>new to programming / even newer to go. having trouble with a small go program - will not compile with undefined variable errors. the code:</p>
  
  <pre><code>package main
  
  import (
    "fmt"
    "io"
    "os"
  )
  
  const file = "readfile.txt" 
  var s string
  
  func lookup(string) (string, string, string) {
      artist := s
      album := s
      year := s
  
      return artist, album, year
  }
  
  func enterdisk() (string, string, string) {
    var artist string
      var album string
      var year string
  
      println("enter artist:")
    fmt.Scanf("%s", &amp;artist)
  
      println("enter album:")
    fmt.Scanf("%s", &amp;album)
  
      println("enter year:")
    fmt.Scanf("%s", &amp;year)
  
      return artist, album, year
  }
  
  func main() {
  
    println("enter UPC or [manual] to enter information manually:")
    fmt.Scanf("%s", &amp;s)
  
      s := s
    switch s { 
          case "manual\n": artist, album, year := enterdisk()
          default: artist, album, year := lookup(s)
    }
  
      f,_ := os.OpenFile(file, os.O_APPEND|os.O_RDWR, 0666) 
    io.WriteString(f, (artist + ", \"" + album + "\" - " + year + "\n")) 
  
      f.Close()
      println("wrote data to file")
  }
  </code></pre>
  
  <p>and the errors:</p>
  
  <pre><code>catalog.go:49: undefined: artist
  catalog.go:49: undefined: album
  catalog.go:49: undefined: year
  </code></pre>
  
  <p>however, those variables will not be defined until the code runs. additionally, the "lookup" function is not yet written, which it just returns what it is passed. i know the lookup and enterdisk functions work on their own, but i am trying to test the switch statement. </p>
  
  <p>i have tried declaring the variables in main, however i get this error:</p>
  
  <pre><code>catalog.go:49: artist declared and not used
  catalog.go:49: album declared and not used
  catalog.go:49: year declared and not used
  </code></pre>
  
  <p>p.s. i have read <a href="http://tip.goneat.org/doc/go_faq.html#unused_variables_and_imports" rel="noreferrer">http://tip.goneat.org/doc/go_faq.html#unused_variables_and_imports</a> , and i agree that if this is only semantics, i still want to fix it. i just don't know how!</p>