Alastair Barnes
Alastair Barnes

Reputation: 11

My program closes immediately? Basic arithmetic. Beginner programmer

I'm inputting a program that I'm to assess into visual studio to see where things are taking place, but it's closing immediately.

Here's the code:

#include <iostream>

int dowork(int a, int b);

int main()
{
using namespace std;

int x = 4, y = 6;
cout << "Welcome to SIT153..." << endl;
x = dowork(x, y);
for (int i = 0; i < x; i++)
{
    int y = i + 3;
    if (y > 6)
        cout << i << " + 3 = " << y << endl;
    else
        cout << "Not yet" << endl;
}
cout << "y = " << y << endl;
return 0;
}

int dowork(int a, int b)
{
return a + b;
}

And here's the debug output

'ConsoleApplication4.exe' (Win32): Loaded 'C:\Users\barne_000\Documents\Visual Studio 2013\Projects\ConsoleApplication4\Debug\ConsoleApplication4.exe'. Symbols loaded.

'ConsoleApplication4.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.

'ConsoleApplication4.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.

'ConsoleApplication4.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.

'ConsoleApplication4.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Cannot find or open the PDB file.

'ConsoleApplication4.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.dll'. Cannot find or open the PDB file.

The thread 0x18dc has exited with code 0 (0x0).

The thread 0x2194 has exited with code 0 (0x0).

The thread 0x1608 has exited with code 0 (0x0).

The program '[9788] ConsoleApplication4.exe' has exited with code 0 (0x0).

Help?

Upvotes: 0

Views: 986

Answers (2)

Pooven
Pooven

Reputation: 1764

After a console application completes, it would normally close. If you want it to rather wait, then you have to specifically use some sort of waiting technique; see here for possible answers.

Upvotes: 1

Waters
Waters

Reputation: 353

Console Windows created by debugging a program will be closed when program exits. Put in a read input at the end (wait for any character ).

Alternatively, run in console window you open, (no debug )

Upvotes: 1

Related Questions