Skip to content

Instantly share code, notes, and snippets.

@1995parham
Created July 22, 2019 20:15
Show Gist options
  • Save 1995parham/8e221188229ea99feb5044fb7886b7fc to your computer and use it in GitHub Desktop.
Save 1995parham/8e221188229ea99feb5044fb7886b7fc to your computer and use it in GitHub Desktop.
Have fun with Scanf
package main
import "fmt"
func main() {
var s []int
for {
var n int
fmt.Println("Please enter the number or zero to exit")
fmt.Scanf("%d", &n)
if n == 0 {
break
} else {
s = append(s, n)
}
}
var sum int
for _, v := range s {
sum += v
}
fmt.Println(sum)
}
@1995parham
Copy link
Author

The above code has an issue with reading from the command line, can you guess the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment