I installed Microsoft Visual C ++ 2010 Express on my netbook, I bought a tutorial on c ++,

I have printed this program from him

#include <iostream> using namespace std ; int main ( ) { // объявлСниС ΠΈ инициализация массива array int array [ ] = { 5, -10, 123, -7, 25, -3, -77, 1, 7, 3 } ; // вычислСниС size β€” количСства элСмСнтов Π² массивС int size = sizeof ( array ) / sizeof ( array [ 0 ] ) ; // ΠΏΡ€Π΅Π΄ΠΏΠΎΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ элСмСнт ΠΈΠΌΠ΅Π΅Ρ‚ индСкс 0 int jMin = 0 ; // Ρ†ΠΈΠΊΠ» ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ элСмСнтов массива for ( int j = 1; j < size; j++ ) if ( array [ j ] < array [ jMin ] ) jMin = j ; // Π²Ρ‹Π²ΠΎΠ΄ массива cout << "Elements of array\n" ; for ( int j = 0; j < size; j++ ) cout << array [ j ] << '\t' ; // Π²Ρ‹Π²ΠΎΠ΄ минимального значСния array [ jMin ] cout << "\nMinimum = " << array [ jMin ] << endl ; exit (0) ; } 

I compile it, the console appears and quickly disappears, do not tell me what the problem is?

  • one
    The program runs to the end and terminates. You even exit (0); prescribed. Do you want the car to execute this code for 20 seconds?)) - Vitaly Kustov
  • If also like in Sharpe, then ctrl + f5 - rasmisha

2 answers 2

As options:

  • At the end of the program, write the getch () function that expects a keystroke. And add to include conio.h.
  • Run in debug mode and put a breakpoint on the last line of the code.
  • @ Andrei2 put a tick next to the answer you like so that the question does not hang in the unanswered - Rules

There are so many options. I will give some of them. The first is to request input from the console:

 int value; cin >> value; 

The second is an infinite loop (not the best option, because it completely loads the processor core):

 for(;;); 

Third:

 system("pause"); 

Only it is necessary for this to connect some kind of header file, I do not remember which one.

  • For system ("pause") to work, the code already has everything you need, std space and iostream. - embarcadero
  • Checked works. - Andrei2
  • one
    Well, if it works, what answer do not you confirm!? - Rimon