0

我使用了 Visual Studio 2012,这是我第一次使用它。我开始了

NEW→<kbd>Project-Empty→<kbd>Project-sourcethen files-add→<kbd>new items-Cpp文件并输入以下代码:

#include <iostream>
using namespace std;
int main()
{
    int cents;
    int dollars, quarters, dimes, nickels, pennies;

    cout << "Enter total cents: ";
    cin >> cents;

    dollars = cents / 100;
    cents = cents - dollars*100;
    quarters = cents / 25;
    cents = cents - quarters*25;
    dimes = cents / 10;
    cents = cents - dimes*10;
    nickels = cents / 5;
    cents = cents - nickels*5;
    pennies = cents;  

    cout << "This corresponds to "
         << dollars << " dollars, "
         << quarters << " quarters, "
         << dimes << " dimes, "
         << nickels << " nickels, and "
         << pennies << " pennies.\n\n";
    return 0;
}

我想编写一个程序将美分分解为dollarsquarters、和nickels,窗口已成功形成,但在我输入美分数后,我想转换的窗口消失了。断点或系统(“暂停”)似乎不起作用。这是消息:dimespennies.exe

'Project2.exe' (Win32): Loaded 'C:\Users\dell\Documents\Visual Studio 2012\Projects\Project2\Debug\Project2.exe'. Symbols loaded. 'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file. 'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file. 'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file. 'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp110d.dll'. Symbols loaded. 'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr110d.dll'. Symbols loaded. The thread 0xe24 has exited with code -1073741749 (0xc000004b). The program '[7476] Project2.exe' has exited with code -1073741510 (0xc000013a).

如何保留.exe窗口并查看结果?

4

3 回答 3

1

程序的返回代码0xc000013a表明按下了 CTRL-C,导致程序退出。您是否按了CTRL-C?

如果您硬编码美分的数量(例如 1999),而不是提示用户输入数字,会发生什么情况?那么它工作正常吗?

如果添加“cin >> cents;”会发生什么?显示计算值的 cout 语句之后?

于 2013-01-22T00:14:58.290 回答
0

如果您要编写控制台程序,您应该从控制台运行它们。如果您想编写一个从 GUI 运行的程序,请编写一个 GUI 程序。

system("pause")没有工作的原因是你从不做cout.flush();cout << endl;。在您实际产生输出之前暂停将无济于事。

于 2013-01-21T23:24:51.357 回答
0

使用ctrl+ F5在没有调试工具的情况下运行您的程序。

于 2013-01-21T23:43:46.103 回答