add chapter 4
This commit is contained in:
23
chapter4/keyboard/keyboard.go
Normal file
23
chapter4/keyboard/keyboard.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package keyboard
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetFloat() (float64, error) {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
input, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
input = strings.TrimSpace(input)
|
||||
number, err := strconv.ParseFloat(input, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return number, nil
|
||||
}
|
||||
Reference in New Issue
Block a user