I have to write a code which takes (integers) numbers from Command-line and keeps reading the terminal until it gets a word END
So I wrote the following; I feel its really bad. Is there any way I can improve below code
I updated my code from previously to below
func main() {
buf := bufio.NewReader(os.Stdin)
lines, err := buf.ReadBytes('\n')
if err != nil {
return
}
fmt.Printf(" %q \n", string(lines))
line := strings.Replace(string(lines), "\n", "", -1)
numbers := strings.Split(line, " ")
fmt.Printf("numbers %q ", numbers)
var sum int64
for _, num := range numbers {
num, err := strconv.ParseInt(num, 10, 0)
if err != nil {
fmt.Println(err)
break
}
sum += num
}
fmt.Println("Sum of all numbers :", sum)
}