0

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?

Pooven
  • 1,744
  • 1
  • 25
  • 44
  • 1
    Actually a code 0 is good news in most environments, as it basically means that the application exited successfully (so no error). What exactly is it, that does not work? I assume you want to see the results of your calculation? As it is not waiting on any I/O of course it will return immediately. The calculations are not that hard after all ;) I've not been using Visual Studio for a while, but how did you create your (console-)application? Like so: https://msdn.microsoft.com/en-us/library/ms235629.aspx ? –  Sep 19 '15 at 13:58
  • Basically it should print out something to a window rather than do nothing. And i'm sure it does something, just really really fast then closes. I need to see the program come up, pause, then allow me to exit. Generally I've just been seeing "press any key to exit" coming up at the end of the cmd window, but now, nothing. – Alastair Barnes Sep 19 '15 at 14:09

2 Answers2

1

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 )

Waters
  • 343
  • 1
  • 11
1

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.

Community
  • 1
  • 1
Pooven
  • 1,744
  • 1
  • 25
  • 44