现在我正在努力学习围棋。
我有代码:
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
var wallCount int
var width, height, area float64
var r = bufio.NewReader(os.Stdin)
fmt.Print("WallCount:")
fmt.Scanf("%d", &wallCount)
fmt.Printf("wallcount = %v \n", wallCount)
for x := 1; x <= wallCount; x++ {
fmt.Printf("wight, height at %v times\n", x)
fmt.Fscanf(r, "%d %d", &width, &height)
area += width * height
}
fmt.Printf("area = %v\n", area)
}
当我编译代码时
在终端上:
WallCount:
进入第 4 学期
WallCount:4
---
wallcount = 4
wight, height at 1 times
wight, height at 2 times
传递到第 1,1 项
WallCount:4
wallcount = 4
wight, height at 1 times
wight, height at 2 times
1,1
---
wight, height at 3 times
wight, height at 4 times
area = 0
你能解释一下吗
为什么我for loops运行第一个 cmd 两次,然后运行第二个 cmd,然后再次运行第一个 cmd 两次,最后运行最后一个 cmd?
为什么area包含 0 ?
红颜莎娜
相关分类