Hello all,
My code asks for a number, then asks for another number. After that it prints each number in order, one over the other.
The odd thing is when I enter numbers with other chars in the number, strange things happen. I’ll show some examples below . My question is, why is this happening? And why is the odd behavior different on Windows and Linux for exactly the same code? These examples were ran on Linux; running this code on Windows show even more bizarre behavior. You’ll need to see the result on a Windows box for yourself.
// Ex.1 Normal run
$ go run numbers1.go
Enter number 1: 5
Enter number 2: 7
5
7
// Ex. 2 Malformed 2nd number - Here the 890 was entered on the second command line automatically
$ go run numbers1.go
Enter number 1: 123
Enter number 2: 567q890
123
567
[user@host.name.com code]$ 890
bash: 890: command not found…
Failed to search for file: Timeout was reached
[user@host.name.com code]$
// Ex. 3 Malformed 1st number - Here I only entered the first number, the second number appeared automatically.
[user@host.name.com code]$ go run numbers1.go
Enter number 1: 123q456
Enter number 2: 123
456
[user@host.name.com code]$
// Ex. 4 Malformed 1st number - Here I only entered the first number, the second number appeared automatically. After “Command not found…” I hit enter a couple of times but nothing happened so I did “CTRL-C”.
[user@host.name.com code]$
go run numbers1.go
Enter number 1: 123qwe456
Enter number 2: 123
0
[user@host.name.com code]$ e456
bash: e456: command not found…
^C
[user@host.name.com code]$
######### Not sure how to put code into code box.
package main
import (
“fmt”
)
func main() {
var num1 int64
var num2 int64
fmt.Print("Enter number 1: ")
fmt.Scan(&num1)
fmt.Print("Enter number 2: ")
fmt.Scan(&num2)
fmt.Println(num1)
fmt.Println(num2)
}
#################