Menu

Nothing appeared to me...plz help me

2009-03-17
2012-09-26
  • Mohammad  Irshid

    Mohammad Irshid - 2009-03-17

    hi all;
    it's the first time i use Dev C++ and i liked it after a lot of stupid errors while useing MV Studio... and for the first time i had tried to test it and i wrote the following code:

    include <iostream>

    using namespace std;

    int main(){
    int list[5];
    int sum=0;

    cout&lt;&lt;&quot;EnterYourNumber&quot;&lt;&lt;endl;
    
    int max=list[0];
    for(int i=0;i&lt;5;i++)
    {
        cin&gt;&gt;list[i];
        sum=sum+list[i];
        if(list[i]&gt;max)
            min=list[i];
    }
      cout&lt;&lt;&quot;Sum=&quot;&lt;&lt;sum&lt;&lt;endl;
      cout&lt;&lt;&quot;da max=&quot;&lt;&lt;max&lt;&lt;endl;
      cout&lt;&lt;endl;
    
    }
    

    No errors and also no warnings, but when built it then pressed on "RUN" the excution .exe appeares to me... and entered 1 2 3 4 5 then enter
    but the .exe closed itself without no results.


    log info:
    Compiler: MhdBadi
    Executing g++.exe...
    g++.exe "C:\Documents and Settings\body\Desktop\maxmin.cpp" -o "C:\Documents and Settings\body\Desktop\maxmin.exe" -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3
    Execution terminated
    Compilation successful


    so i don't know why it closed itself before show the results

    plz help me because i have a final exam after 2 days
    note: i'm using Windows XP Professional SP3

     
    • cpns

      cpns - 2009-03-18

      It is normal behaviour in Windows (and probably all other GUI environments) that when a process terminates, its window is closed. Your program is not magically any different. If you did not write code to prevent your application from terminating, then it did exactly what you coded it to do.

      This 'problem' is so common it is dealt with in the "PLEASE READ BEFORE POSTING A QUESTION*" thread in this very forum!

      Some environments (such as VC++) execute IDE launched processes as a child process of another so that the program does not own the window so it does not close. Dev-C++ does not do that. Don't ask me why.

      Another solution is to run the code in the debugger, with a breakpoint at the end of main(). But to be honest, if you get the debugger in Dev-C++ to work reliably, you are a better man than I. To be honest, you are going backward if you abandoned VC++ in favour of Dev-C++.

      Clifford

       
    • Mohammad  Irshid

      Mohammad Irshid - 2009-03-18

      Thanks a lot Clifford for your careness, but the point u didn't get is that any program u ever run must give you your result before closing the command window showing a sentense asking you to press any key to continue and run out from your program, but my one is running out before showing any results and that what am asking about.
      Thanks again

       
    • cpns

      cpns - 2009-03-18

      > but the point u didn't get

      I can assure you that I "got the point" and you are wrong. If you do not write your program to wait for a key press it should terminate.

      The only reason that you get that help in VC++ is because your program is run within another program that does that for you.

      > any program u ever run must give you your result before closing

      Well that is not true, not all programs must necessarily have visible console output. However in your case the output was displayed, and your program terminated, and its window closed. The results were displayed for so short a time you did not see them.

      > showing a sentense asking you to press any key to continue

      Only if you either write that code to run from within an environment that does that for you. This is not normal behaviour and would be undesirable if say a program was to be executed as part of a batch process.

      I suggest that you take any program that you wrote in VC++ where you expect the "press any key" prompt and run it directly from Explorer. You will find that it behaves in exactly the same way as running a program from within Dev-C++. The wait prompt is provided by the IDE not the compiler - it is not part of the application.

      There was a time when this question came up two or three times a week or more. That is why the solution is provided in the Read First thread. You have shown no evidence yet that you have in fact read it.

      Now it would be nice if Dev-C++ provided the "press any key" service as a convenience, and it would have been simple for the developers to have implemented it, but they didn't, so live with it and stop railing against 'by design' behaviour.

      Clifford

       
    • tleeski

      tleeski - 2009-05-04

      I see this is an old thread, but, include these lines:

         system(&quot;PAUSE&quot;);
         return 0;
      

      before the last }

       
      • Wayne Keen

        Wayne Keen - 2009-05-04

        lease do not "bump" old thread like this.

        It interferes with current topics.

        Wayne

         
      • cpns

        cpns - 2009-05-04

        I see you too have missed the point entirely. That is exactly the same information provided in the "read first" thread he was directed to, so the question is answered.

        Since that thread also contains a lot of other useful information he will want to know, (and he should have read it in any case, hence its name), it is useful to encourage the poster to go there for the answer rather than spoon feed it. If you do that they never gain any self reliance and keep coming back for more.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.