trouble seeing finished product

Hello,

I am having trouble seeing my finished product. Basically, I run the program and at the very last line of code, it executes, and then the screen disappears. Thus, I cannot see the final step.

Here is an example of some code I have been toying with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main()
{
    int size;
        cout << "enter size of data array: ";
        cin >> size;
    
    double data[size]; //declare array of data
    double datum;
    int i;
     for(i = 0; i < size; i++){ 
                  cout << "enter data: ";
                  cin >> datum;
                  data[i] = datum;}
    //output the new data array
    cout << "data array = {" << data[i] << "}";
  return 0;
}


I want to fill an array of a user defined size with user defined data. In the last line of code I ask to see the array. When that line executes the display box the program is running in vanishes. As a result, I never get to see the last line!

So...how do I fix this?

Thanks
Last edited on
1. change your IDE to one that keeps the output window open until you stop your code, or,
2. run the code from command line, or,
3. write a code that makes your program pause and insert it into your code e.g: http://www.cplusplus.com/forum/beginner/1988/

p/s line 18 in your code is wrong :)
If you use Code::Blocks, it will keep the output window open at the end of your code.
Use: system("PAUSE") if your looking for a quick only windows method, or cin.get().
Use: define end as a string then at the end of the code do cin >> end;
Topic archived. No new replies allowed.