# Visual studio code newbie cant debug its first program



## grandekid (Sep 25, 2017)

Hello,
Newbie here, i cant debug my first program.(skip the wrong file names,i will change)
http://prntscr.com/gpghaz


----------



## EarthDog (Sep 25, 2017)

First, you should learn how to attach images to the forum instead making people click on links... Let's start with that before something more advanced.


----------



## grandekid (Sep 25, 2017)

if thats the case


----------



## dcf-joe (Sep 25, 2017)

If you are declaring your Main function as an integer, should it not have to return a value?

It has been a while since I have done C/C++, but should it not return zero at the very end to let the operating system know to stop execution?


----------



## Flaky (Sep 25, 2017)

It does not have to. It is a special case - if main does not return anything explicitly, it returns 0. 
Remember that there is no such rule in C - main will return junk.


----------



## Mindweaver (Sep 25, 2017)

grandekid said:


> if thats the case



You can always put your code in *[code] [/code]* BB Code as well.

Example:

[code]
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, World!";
    return 0;
}
[/code]


Adding the above will display like what's below. This will help other users when trying to debug your code or help out.


```
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, World!";
    return 0;
}
```


----------



## dcf-joe (Sep 25, 2017)

```
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string name, Lname;
    int age;

    cout << "Enter your first name:  ";
    cin >> name;

    cout << "Enter your last name:  ";
    cin >> Lname;

    cout << "Enter your age:  ";
    cin >> age;

    cout << "\n" << name << " " << Lname << " is " << age << " years old." << "\n" << "\n";

    system("pause");

    return 0;
}
```

I use Visual Studio 2017 in a Windows environment and I got your program to work making some minor modifications.

The biggest change was I always thought you had to include the string header whenever using strings. I also think that using cin with strings become more stable with the header included.


----------



## grandekid (Sep 25, 2017)

Thank you all for your posts. Any idea how can i fix?


----------



## Mindweaver (Sep 25, 2017)

Did you check to see if the path is correct? Try opening "e:\VSCODE PROJECTS\HELLO WORLD\" to see if the HW.ccp file exists using explorer to verify.


----------



## dcf-joe (Sep 25, 2017)

grandekid said:


> Thank you all for your posts. Any idea how can i fix?View attachment 92433



I've never had to deal with that, but it seems like it's actually a common issue on google. This might be able to help, you might have to tell Visual Studio where some other files are:  https://github.com/Microsoft/vscode/issues/28257


----------



## grandekid (Sep 25, 2017)

Managed to make a small progress,now i got this.



the code is (launch.json)

```
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "E:\\VSCODE PROJECTS\\HELLO WORLD\\HW.cpp",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true
}
]
}
```

main program

```
#include <iostream>
using namespace std;

int main()
{
cout << "Hello, World!";
return 0;
}
```


----------

