TRTGA
TRTGA

Reputation: 3

VSCode runs in debug console for some reason

For some reason, VSCode exclusively runs in the debug console, regardless of if I run with/without debugging. As such, it won't recognise user input, and that's a relatively big problem. It's probably an easy fix, but hoping someone can give me solid advice on how to fix it. I'll stick the actual code I'm running underneath:

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func add(one int, two int) int {
    var three = one + two

    return three
}

func main() {
    var s []int

    one := 0
    two := 1
    input1 := bufio.NewScanner(os.Stdin)
    fmt.Println("How many places of the Fibbonaci sequence? ")
    input1.Scan()
    numplac := input1.Text()
    places, err := strconv.Atoi(numplac)
    _ = err

    for i := 0; i < places; {
        s = append(s, one)
        i++
        if i < places {
            s = append(s, two)
            i++
            one = add(one, two)
            two = add(one, two)
        } else {
            fmt.Printf("Finished at: %d \n", places)
        }
    }
    fmt.Println("Fibbonaci to", places, "places:")
    fmt.Println(s)
    for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
        s[i], s[j] = s[j], s[i]
    }
    fmt.Println("Fibbonaci to", places, "places, reversed:")
    fmt.Println(s)
}

Cheers.

Upvotes: 0

Views: 94

Answers (1)

Oleg Butuzov
Oleg Butuzov

Reputation: 5405

Currently go support in visual studio code doesn't work console option (so you can use "console": integratedTerminal) (see reference). You can see a warning about it if you added.

Your options:

  1. Provide input via args, env or envFile (see reference).
  2. Use something like code runner extension, but without debugging.

Upvotes: 1

Related Questions