Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

very basic dev-c++ question

Options
  • 13-11-2005 11:49pm
    #1
    Closed Accounts Posts: 1,299 ✭✭✭


    Ok I am used to using sub etha edit on macs, yet when I try to use dc++ some of my programmes just suddenly close,

    this is a stupid example which does work


    //?//
    #include <iostream>
    using namespace std;

    int main (){
    double a,b,c,e,f,g,h,i;

    cout << "Enter a value for a ";
    cin >> a;
    cout << " Enter a value for b ";
    cin >>b;
    cout << "Enter a value for c ";
    cin >>c;
    e= + a + b +c;
    cout << "The value of " << e << "is" << endl;
    cin >> f;
    cout << f;
    cin >> g;
    h=(2*45*34*a)-(b*c*e);
    cout <<h;
    cin >> i;
    return 0;
    };


    the problem is that whenever i make a cout <<
    line and dont follow it up with c cin >> line
    the programme closes, it is as if everytime I write a cout it must be asking for a value


    Any ideas,

    sorry if this is obvious/unclear.


Comments

  • Registered Users Posts: 2,002 ✭✭✭bringitdown


    Well cin will block awaiting input so the program will stop executing and await a 'user' to input something.

    If you have no blocking statements in your program, for example if you have:
    #include <iostream>
    using namespace std;
    
    int main (){
    
    cout << "This program will close immediately";
    
    return 0;
    };
    

    The program will execute the whole way through and close. To see output from such a program run it in a console / command-prompt (Mac OS X has one, previous versions?)


  • Closed Accounts Posts: 1,299 ✭✭✭Sandals


    ok great, that is what I am talking about, but can I get a console for windoes, where?


  • Registered Users Posts: 2,002 ✭✭✭bringitdown


    For windows, the command line interpreter will do

    Start->Run->command
    OR
    Start->Run->cmd

    You will have to navigate to the directory your application / binary is in using DOS commands:

    cd c:
    cd SomeDir
    etc
    etc


  • Closed Accounts Posts: 1,061 ✭✭✭dawballz


    Just before your
    return 0;
    

    put in:
    cin.get();
    

    Then, when you run the program, it will do whatever else it is doing, then you'll get an _, then just press enter and it closes..
    Gives you a chance to see stuff that is output.


  • Closed Accounts Posts: 7 Noogop


    just add the line

    system("PAUSE");

    before your return 0;
    it will make the program output the line
    "Press any key to continue . . ."
    before closing, you just hit return to end the program


  • Advertisement
  • Closed Accounts Posts: 1,299 ✭✭✭Sandals


    Ok thanks noogop, so much that is perfect I really apreciate it , all the other advice was lame and did'nt work.


  • Registered Users Posts: 2,002 ✭✭✭bringitdown


    All the other advice ... last time you get jack from me.

    I explained the problem and gave you pointers on how to solve it, noogop gave you 'an' answer, one I wouldn't agree with but anyhoo on your merry way.


Advertisement