C++ Program Execution

Discussion in 'C++' started by Alexander.David.R@gmail.com, Oct 20, 2005.

  1. Guest

    Hello,

    I have been getting to know C and C++ alot lately and have come up with
    the same problem with each program that I write. When I compile the
    program, it comes out with no errors. I can solve those no problem
    (usually just a misplaced semicolon) but when it comes to executing the
    program to verify my program works correctly, after I input one or
    sometimes two variables it closes the window that it is running in. I
    have tried using both Visual Studio 2003 and Dev-C++ to compile and run
    the programs and it does the same thing in each. Anyone have an ideas
    as to why this is happening? I will include code for one that I am just
    starting off writing in this post to help you see what is writen.
    Thanks in advance for all help recieved.

    David

    // Code Start:
    #include <iostream>

    int main()
    {
    char name;
    int age = 0;

    std::cout << "Enter your name: ";
    std::cin >> name;
    std::cout << "Enter your age: ";
    std::cin >> age;
    std::cout << "\nName: ";
    std::cout << name;
    std::cout << "\nAge: ";
    std::cout << age;
    }
    // End Code
     
    , Oct 20, 2005
    #1
    1. Advertising

  2. osmium Guest

    <> wrote:


    > I have been getting to know C and C++ alot lately and have come up with
    > the same problem with each program that I write. When I compile the
    > program, it comes out with no errors. I can solve those no problem
    > (usually just a misplaced semicolon) but when it comes to executing the
    > program to verify my program works correctly, after I input one or
    > sometimes two variables it closes the window that it is running in. I
    > have tried using both Visual Studio 2003 and Dev-C++ to compile and run
    > the programs and it does the same thing in each. Anyone have an ideas
    > as to why this is happening? I will include code for one that I am just
    > starting off writing in this post to help you see what is writen.
    > Thanks in advance for all help recieved.
    >
    > David
    >
    > // Code Start:
    > #include <iostream>
    >
    > int main()
    > {
    > char name;
    > int age = 0;
    >
    > std::cout << "Enter your name: ";
    > std::cin >> name;
    > std::cout << "Enter your age: ";
    > std::cin >> age;
    > std::cout << "\nName: ";
    > std::cout << name;
    > std::cout << "\nAge: ";
    > std::cout << age;
    > }
    > // End Code


    Try adding this just before the closing brace in main.

    cin.get();
     
    osmium, Oct 20, 2005
    #2
    1. Advertising

  3. Jay Nabonne Guest

    On Thu, 20 Oct 2005 14:37:52 -0700, wrote:

    > Hello,
    >
    > I have been getting to know C and C++ alot lately and have come up with
    > the same problem with each program that I write. When I compile the
    > program, it comes out with no errors. I can solve those no problem
    > (usually just a misplaced semicolon) but when it comes to executing the
    > program to verify my program works correctly, after I input one or
    > sometimes two variables it closes the window that it is running in. I
    > have tried using both Visual Studio 2003 and Dev-C++ to compile and run
    > the programs and it does the same thing in each. Anyone have an ideas
    > as to why this is happening? I will include code for one that I am just
    > starting off writing in this post to help you see what is writen.
    > Thanks in advance for all help recieved.
    >


    If you're debugging it: set a breakpoint on the close brace of main.
    If you're not debugging it: run from a separate command window.

    - Jay
     
    Jay Nabonne, Oct 20, 2005
    #3
  4. red floyd Guest

    wrote:
    > Hello,
    >
    > I have been getting to know C and C++ alot lately and have come up with
    > the same problem with each program that I write. When I compile the
    > program, it comes out with no errors. I can solve those no problem
    > (usually just a misplaced semicolon) but when it comes to executing the
    > program to verify my program works correctly, after I input one or
    > sometimes two variables it closes the window that it is running in. I
    > have tried using both Visual Studio 2003 and Dev-C++ to compile and run
    > the programs and it does the same thing in each. Anyone have an ideas
    > as to why this is happening? I will include code for one that I am just
    > starting off writing in this post to help you see what is writen.
    > Thanks in advance for all help recieved.
    >
    > David
    >
    > // Code Start:
    > #include <iostream>
    >
    > int main()
    > {
    > char name;
    > int age = 0;
    >
    > std::cout << "Enter your name: ";
    > std::cin >> name;
    > std::cout << "Enter your age: ";
    > std::cin >> age;
    > std::cout << "\nName: ";
    > std::cout << name;
    > std::cout << "\nAge: ";
    > std::cout << age;

    std::cout << std::endl;
    cin.get();
    > }
    > // End Code
    >
     
    red floyd, Oct 21, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. priya
    Replies:
    0
    Views:
    1,238
    priya
    Oct 3, 2005
  2. Pat Deegan
    Replies:
    3
    Views:
    486
    Joe Smith
    Apr 22, 2004
  3. varala_kanth

    execution of perl program

    varala_kanth, Jun 26, 2004, in forum: Perl
    Replies:
    1
    Views:
    4,189
    J├╝rgen Exner
    Jun 26, 2004
  4. wang
    Replies:
    3
    Views:
    15,332
  5. seenuvas
    Replies:
    7
    Views:
    2,663
    Roedy Green
    Jan 24, 2006
Loading...

Share This Page