TMK
TMK

Reputation: 81

Execution of code stuck on running in VSCode

So I have preinstalled extension like 'Code Runner' and 'C/C++' in Vscode.

The problem I am facing is in running a code which gets stuck on running :

#include <stdio.h>
#include <stdlib.h>

int main()
{
    //program to convert minutes into years and days
    int min = 0;
    double yrs = 0.0;
    double days = 0.0;
    double min_in_yr = 0;
    printf("Enter the nmuber of minutes: ");

    //get input from the user
    scanf("%d", &min);

    //calculation
    min_in_yr = (60 * 24 * 365);


    yrs = (min / min_in_yr);
    days = (yrs * 365);

    printf("%d minutes is approx %f years and %f days\n", min, yrs, days);



    return 0;
}

There is no problem with the code as it seems to be running fine on CodeBlocks.

Also I tried executing a simple hello world program which seemed to be executed perfectly on Vscode in 1.8 s.

What could be the problem?

Upvotes: 2

Views: 11120

Answers (1)

TMK
TMK

Reputation: 81

So I looked up and found a solution for this problem.May it helps other beginners who get stuck doing this on Vscode.

So the problem is actually with the scanf function which seems to be not compatible with OUTPUT section of the output panel.I don't know the reason for this but I found a alternate way to do this.

Just make your code run in the terminal instead.

To do this:

1.Make sure you have code runner extension installed

2.Goto File>Preferences>Settings>Extensions>Run Code configuration and under that scroll down to search for Code Runner:Run in Terminal and check that option.If you are not able to find that search in settings for text in bold and you find

3.That's it.Run your code and it will automatically be executed in the terminal

Upvotes: 4

Related Questions