diff --git a/golangr/between-1-10-checker/compare.go b/golangr/between-1-10-checker/compare.go index 24ffa3b..971e200 100644 --- a/golangr/between-1-10-checker/compare.go +++ b/golangr/between-1-10-checker/compare.go @@ -2,6 +2,8 @@ package main import "fmt" +// TODO: Figure out error handling and prevent people from breaking this + func compare(number float64) { if number >= 1 && number <= 10 { fmt.Printf("%v is between 1 and 10\n", number) diff --git a/golangr/between-1-10-checker/nameget.go b/golangr/between-1-10-checker/nameget.go index 0c2e223..6656530 100644 --- a/golangr/between-1-10-checker/nameget.go +++ b/golangr/between-1-10-checker/nameget.go @@ -1,20 +1,28 @@ package main import ( + "bufio" "fmt" - "log" + //"log" + "os" ) func nameget() { - fmt.Println("Welcome to this simple program, may I know your name?\n(Please don't use spaces, I still haven't figured out how to parse them all together into a string)") + fmt.Println("Welcome to this simple program, may I know your name?\n(You can use spaces now, I figured out how to use the bufio library)") fmt.Printf("Name: ") + reader := bufio.NewReader(os.Stdin) + name, _ = reader.ReadString('\n') + + // Hold that thought, I'm pretty sure bufio might be infinitely better, scan keeps bothering me by not + // accepting spaced out words + // It has come to my attention that scan actually spits out two values, default and err - _, err := fmt.Scanln(&name) + // _, err := fmt.Scanln(&name) // nil is literally the equivalent of null, we're just checking here if err is not null, // and if it isn't, it means an error has ocurred so we're just gonna panic and kill the program - if err != nil { - log.Fatal(err) - } + // if err != nil { + // log.Fatal(err) + // } } diff --git a/golangr/between-1-10-checker/startup.go b/golangr/between-1-10-checker/startup.go index 444887b..00bd0fd 100644 --- a/golangr/between-1-10-checker/startup.go +++ b/golangr/between-1-10-checker/startup.go @@ -1,9 +1,14 @@ package main -import "fmt" +import ( + "fmt" + "strings" +) func startup(number float64) { - fmt.Printf("Alright %s, give me a number, I will tell you if it's between 1 and 10\n", name) + // Oh man I gotta use another library, strings lets me trim pretty easily any string and since bufio + // seems to append newlines to everything I'm gonna have to make use of this + fmt.Printf("Alright %s, give me a number, I will tell you if it's between 1 and 10\n", strings.TrimRight(name, "\n")) fmt.Printf("Number: ") fmt.Scan(&num) return