Created
July 22, 2019 20:15
-
-
Save 1995parham/8e221188229ea99feb5044fb7886b7fc to your computer and use it in GitHub Desktop.
Have fun with Scanf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above code has an issue with reading from the command line, can you guess the issue?