On Tue, Jan 22, 2019 at 11:40 AM John <[email protected]> wrote:
> Dear Gophers,
>
> I have recently made a project of Connect Five. When the imput is wrong it
> will have a goroutine problem that says something about out of index, as my
> game win function depends on if the x = b and x+1 = b and so on. But if the
> imput is not 1,2 1,3 and so on, or it is over 15, 15 it will be wrong. I
> made a solution of creating a function like this:
>
> func fix() {
> if x == "1"|| x == "2"|| x == "3"|| x == "4"|| x == "5"|| x == "6"|| x ==
> "7"|| x == "8"|| x == "9"|| x == "10"|| x == "11"|| x == "12"|| x == "13"||
> x == "14"|| x == "15" {
> if y == "1"|| y == "2"|| y == "3"|| y == "4"|| y == "5"|| y == "6"|| y ==
> "7"|| y == "8"|| y == "9"|| y == "10"|| y == "11"|| y == "12"|| y == "13"||
> y == "14"|| y == "15" {
> blwi()
> } else {
> showBoard()
> fmt.Println("Sorry you had entered wrong please enter again")
> fmt.Scanln(&x,&y)
> fix()
> }
> }
>
> It for some reason won't work. So I wonder if any of you can help me
> correct the function and simplify it. (it goes right between the imput and
> the win function.)
>
You don't have an "else" case if the x value is out of bounds; it only
handles the y value error condition.
Also, it would be a lot more simple if you were dealing with ints instead
of strings:
func fix(x, y int) {
if 1 > x || x > 15 {
handleError()
}
if 1 > y || y > 15 {
handleError()
}
proceed()
}
You could always scan them to ints and test them as ints, and then convert
to string if your app logic needs it.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.