我的程序立即关闭?基本算术。初级程序员

My program closes immediately? Basic arithmetic. Beginner programmer

我正在将我要评估的程序输入 visual studio 以查看发生的情况,但它会立即关闭。

代码如下:

#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;
}

这是调试输出

'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).

帮忙?

通过调试程序创建的控制台Windows将在程序退出时关闭。在末尾放入读取输入(等待任何字符)。

或者,运行 在控制台 window 打开,(无调试)

控制台应用程序完成后,通常会关闭。如果你想让它等待,那么你必须专门使用某种等待技术;请参阅 here 了解可能的答案。