【发布时间】:2018-04-16 20:22:59
【问题描述】:
我正在尝试在 Go 中制作一个基本的加法计算器(在这里完成新手),但每次我得到的输出都是 0。
这是代码:
package main
import (
"fmt"
"strconv"
//"flag"
"bufio"
"os"
)
func main(){
reader := bufio.NewReader(os.Stdin)
fmt.Print("What's the first number you want to add?: ")
firstnumber, _ := reader.ReadString('\n')
fmt.Print("What's the second number you want to add?: ")
secondnumber, _ := reader.ReadString('\n')
ifirstnumber, _ := strconv.Atoi(firstnumber)
isecondnumber, _ := strconv.Atoi(secondnumber)
total := ifirstnumber + isecondnumber
fmt.Println(total)
}
【问题讨论】:
标签: go calculator strconv