RandyHuang
RandyHuang

Reputation: 31

.exe window exit after

I used visual studio 2012 and this is my first time to use that. I started wth

NEWProject-EmptyProject-sourcethenfiles-addnew items-Cpp file and input the following codes:

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

I want to make a program to break down cents into dollars, quarters, nickels, dimes and pennies, the .exe window was successfully formed but after I entered the number of cents I want to convert the window disappeared. breakpoint or system("pause") seems don't work. And here is the messages:

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

How can I keep the .exe window and see the result?

Upvotes: 0

Views: 1178

Answers (3)

Nik Bougalis
Nik Bougalis

Reputation: 10613

The return code 0xc000013a from the program suggests that CTRL-C was pressed, causing the program to exit. Did you press CTRL-C perchance?

What happens if you hard-code the number of cents (e.g. say to 1999), instead of prompting the user to enter a number? Does it work correctly then?

What happens if you add a "cin >> cents;" after the cout statement showing the calculated values?

Upvotes: 1

Mikhail
Mikhail

Reputation: 8028

Use ctrl+ F5 to run your program without debugging tools.

Upvotes: 0

David Schwartz
David Schwartz

Reputation: 182743

If you're going to write console programs, you should run them from a console. If you want to write a program to run from a GUI, write a GUI program.

The reason system("pause") didn't work is that you never do cout.flush(); or cout << endl;. Pausing before you actually produce output won't help.

Upvotes: 0

Related Questions