1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Visual studio code newbie cant debug its first program

Discussion in 'Programming & Webmastering' started by grandekid, Sep 25, 2017.

  1. grandekid

    Joined:
    Aug 12, 2017
    Messages:
    60 (0.83/day)
    Thanks Received:
    6
  2. EarthDog

    EarthDog

    Joined:
    Dec 31, 2009
    Messages:
    10,736 (3.76/day)
    Thanks Received:
    5,834
    Location:
    Ohio
    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. :)
     
  3. grandekid

    Joined:
    Aug 12, 2017
    Messages:
    60 (0.83/day)
    Thanks Received:
    6
    [​IMG]if thats the case
     
    EarthDog says thanks.
  4. dcf-joe

    dcf-joe

    Joined:
    Feb 11, 2008
    Messages:
    527 (0.15/day)
    Thanks Received:
    155
    Location:
    Lincoln, Nebraska, USA
    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?
     
  5. Flaky

    Joined:
    Aug 18, 2017
    Messages:
    31 (0.46/day)
    Thanks Received:
    15
    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.
     
  6. Mindweaver

    Mindweaver Moderato®™ Staff Member

    Joined:
    Apr 16, 2009
    Messages:
    6,518 (2.09/day)
    Thanks Received:
    3,879
    Location:
    Charleston, SC
    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.

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        cout << "Hello, World!";
        return 0;
    }
    
     
    Last edited: Sep 25, 2017
    grandekid says thanks.
    Crunching for Team TPU
  7. dcf-joe

    dcf-joe

    Joined:
    Feb 11, 2008
    Messages:
    527 (0.15/day)
    Thanks Received:
    155
    Location:
    Lincoln, Nebraska, USA
    Code:
    #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.
     
    Last edited: Sep 25, 2017
    Mindweaver says thanks.
  8. grandekid

    Joined:
    Aug 12, 2017
    Messages:
    60 (0.83/day)
    Thanks Received:
    6
    Thank you all for your posts. Any idea how can i fix? upload_2017-9-25_16-39-36.png
     
  9. Mindweaver

    Mindweaver Moderato®™ Staff Member

    Joined:
    Apr 16, 2009
    Messages:
    6,518 (2.09/day)
    Thanks Received:
    3,879
    Location:
    Charleston, SC
    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.
     
    Crunching for Team TPU
  10. dcf-joe

    dcf-joe

    Joined:
    Feb 11, 2008
    Messages:
    527 (0.15/day)
    Thanks Received:
    155
    Location:
    Lincoln, Nebraska, USA
  11. grandekid

    Joined:
    Aug 12, 2017
    Messages:
    60 (0.83/day)
    Thanks Received:
    6
    Managed to make a small progress,now i got this.
    upload_2017-9-25_17-26-57.png
    the code is (launch.json)
    Code:
    {
    "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
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    cout << "Hello, World!";
    return 0;
    }
    
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)