dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: implicit declaration of function 'int system(...)

  1. #1
    Join Date
    May 2008
    Posts
    4

    Red face implicit declaration of function 'int system(...)

    Hey everybody, I am new to this forum and C++, But i would love to start

    Okay so i will start off by giving you my code
    _________________________________________________________

    #include<iostream>
    using namespace std;

    int main(void)
    {

    double dnumber1 = 0.0;
    double dnumber2 = 0.0;
    double dnumber3 = 0.0;
    double daverage = 0.0;

    cout <<"Please enter 3 numbers! " << endl;
    cin >> dnumber1;
    cin >> dnumber2;
    cin >> dnumber3;

    daverage = (dnumber1 + dnumber2 + dnumber3) / 3;

    cout << "the average of the numbers is: " << daverage << endl;
    system("PAUSE");
    return 0;

    }

    _______________________________________________________

    And when I try to compile it I get this error :

    implicit declaration of function 'int system(...)'
    so i think something is wrong with line 20
    system("pause");
    I think that line means that the program will not close when you enter in all your info

    Oh, and if it means anything i am using dev c++
    Thanks for your help

  2. #2
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: implicit declaration of function 'int system(...)

    Welcome to the forum!

    Please use code tags when posting codes

    Code:
    daverage = (dnumber1 + dnumber2 + dnumber3) / 3;
    this causes implicit conversion between double and integers
    because you're dividing the sum of the doubles by an integer.
    you need to explicitly indicate the type of the divsior, some like this
    Code:
    daverage = (dnumber1 + dnumber2 + dnumber3) / 3.0;
    .

    I feel like there's something more I need to tell you but can't think of it now.
    hope this helps!

  3. #3
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: implicit declaration of function 'int system(...)

    Please see this thread http://www.codeguru.com/forum/showth...25#post1722919 for one discussion (out of many), why you should NOT use that technique....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  4. #4
    Join Date
    May 2008
    Posts
    4

    Re: implicit declaration of function 'int system(...)

    Thank you for your replies,
    I replaces 3 with 3.0 and it still gives me the same error

    I would appreciate some help

    Thanks

  5. #5
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: implicit declaration of function 'int system(...)

    The double/int thing isn't relevant to the error. In fact, it was just fine the other way in this case, although that sort of thing *is* worth watching out for, particularly when all of your operands are ints and you want a double result (which isn't the case here).

    That error means you aren't including the header file that declares the function system(), so the program has no idea what a call to that function should look like. I think it's in <stdlib.h>, AKA <cstdlib>.

    I think that line means that the program will not close when you enter in all your info
    That line means the program will wait for an additional keypress before exiting. Nothing more or less. You could achieve the almost the same thing with a cin.get() call.

  6. #6
    Join Date
    May 2008
    Posts
    4

    Re: implicit declaration of function 'int system(...)

    Thank you so much, stdlib.h Worked

    THANK YOU

  7. #7
    Join Date
    Jun 2007
    Location
    Pakistan
    Posts
    61

    Re: implicit declaration of function 'int system(...)

    Quote Originally Posted by aaronson2012
    Hey everybody, I am new to this forum and C++, But i would love to start
    So, welcome to the forum and enjoy the new language!
    Quote Originally Posted by aaronson2012
    Okay so i will start off by giving you my code
    Please always use Code tags for proper indentation of your code.
    Quote Originally Posted by aaronson2012
    implicit declaration of function 'int system(...)'
    type #include<stdlib.h> at the beginning of program. Actually system function is defined in this file. By including it, you tell the compiler to use that system function.
    Quote Originally Posted by aaronson2012
    I think that line means that the program will not close when you enter in all your info
    system() function is a way to communicate with the operating system. By providing PAUSE, you tell the operating system to halt the execution and wait for user input, so that user can see the output of your program.
    Thanks.
    Anwar-ul-Haque

  8. #8
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: implicit declaration of function 'int system(...)

    sorry aaronson2012, I read your question wrong.
    Lindley is correct.

    I've been learning C++ for the past few months and I didn't know system() resides in cstdlib header till today.
    when you open an empty file in dev c++,
    the file already has cstdlib header and system("pause").
    This is something I overlooked.
    so I recommend that you open your notepad,
    write a simple code and compile it from the command line!

    and fyi, I heard dev c++ is no longer maintained.
    maybe you should get another IDE such as Code::Block or Eclipse

    thanks!

  9. #9
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: implicit declaration of function 'int system(...)

    Quote Originally Posted by anwar4849
    system() function is a way to communicate with the operating system. By providing PAUSE, you tell the operating system to halt the execution and wait for user input,
    Close, but not quite. You're telling your program to wait while the operating system runs a program that waits for user input, not telling the OS itself to wait.

    so that user can see the output of your program.
    While it's sometimes used this way, that is not the best way of thinking about it. What you're doing is preventing your program from exiting. There are other ways you could do this, arguably better; this way just happens to be convenient.

  10. #10
    Join Date
    Jun 2007
    Location
    Pakistan
    Posts
    61

    Re: implicit declaration of function 'int system(...)

    Quote Originally Posted by Lindley
    Close, but not quite. You're telling your program to wait while the operating system runs a program that waits for user input, not telling the OS itself to wait.
    Oops!!!
    Yes you are right! My Mistake.

  11. #11
    Join Date
    Apr 1999
    Posts
    27,449

    Re: implicit declaration of function 'int system(...)

    Quote Originally Posted by TheCPUWizard
    Please see this thread http://www.codeguru.com/forum/showth...25#post1722919 for one discussion (out of many), why you should NOT use that technique....
    All of a sudden, there seems to be a flurry of threads where posters do not know how to use the command-line to run a program.

    Have I been out of the loop on this over the years? It was a given that console programs were run from the command-line.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)