package main
import (
"fmt"
"bufio"
"os"
)
func main() {
fmt.Print("LOADED!\n")
fmt.Print("insert y value here: ")
inputY := bufio.NewScanner(os.Stdin)
inputY.Scan()
inputXfunc()
}
func inputXfunc() {
fmt.Print("insert x value here: ")
inputX := bufio.NewScanner(os.Stdin)
inputX.Scan()
slope()
}
func slope() {
fmt.Println(inputX.Text())
}
Run Code Online (Sandbox Code Playgroud)
每当我运行这个程序时,它说,inputX和inputY都是未识别的.如何使此程序使用所有函数都可访问的变量?我想做的就是通过inputX分配inputY然后打印出结果
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
fmt.Println("insert y value here: ")
input := bufio.NewScanner(os.Stdin)
fmt.Println(input.Text)
}
Run Code Online (Sandbox Code Playgroud)
如何让程序等待,直到用户输入数据?
package main
import (
"fmt"
"math"
)
func main() {
// x= +- sqrtB-4ac/2a
cal()
}
func cal() {
b := 3
a := 4
c := 2
b2 := float64(b*b)
ac := float64(4)*float64(a)*float64(c)
q := math.Sqrt(b2-ac)
fmt.Print(q)
}
Run Code Online (Sandbox Code Playgroud)
这将输出NaN,但为什么.我正在尝试制作二次计算器.我想要的就是输出数字.
go ×3