Thread: function call question?

  1. #1
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    function call question?

    Greetings,
    I have a question as to whether this statement can be used to call the function Calculate(). I compile it and it has errors by any chance does anyone else able to call the function or yet? Pls respond...



    Code:
    #include <iostream.h>
    
    void Calculate(double a, double & b,
    			   int m, int &k, int & n, char &c);
    
    int main()
    {
       	
    	const double PI = 3.14159;
    	const int TWO = 2;
    	const char INITIAL = 'N';
    
    	int month, day, year, p, q;
    	double hours, rate, amount, u, v;
    	char code, dept;
    
    }
    
    Calculate(13, hours, PI, 13, year, dept);

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    You need to define the function like you have done with main, using {}.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You also cannot call a function at file scope, the call itself must be inside of another function. Though this may be a typo.

    -Prelude
    My best code is written with the delete key.

  4. #4
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Wink Greeting Prelude!

    You also cannot call a function at file scope, the call itself must be inside of another function. Though this may be a typo
    I have typed it exactly from the textbook but its puzzlling to me because of all the different undeclared variables and it even has a redifition. I am confused to what it means by can I use it to call the function. My answer would be yes, you can call it, right. You can't run it because the compiler comes up with the different errors.
    pls explain.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You got that from a book?

    Well, there are plenty of problems, like not using standard headers, calling a function in file scope, oodles of unused variables, one really stupid macro, and trying to pass constant values to a function as a reference parameter. This is a bit better:
    Code:
    #include <iostream.h>
    
    const double PI = 3.14159;
    const char INITIAL = 'N';
    const int TWO = 2; // Awful, awful name. What's the point of this macro?
    
    void Calculate(double a, double &b, double m, int k, int &n, char &c);
    
    int main()
    {
      int year;
      double hours;
      char dept;
      
      Calculate(13.0, hours, PI, 13, year, dept);
      
      return 0;
    }
    
    // Definition of Calculate goes here
    What exactly was the book trying to accomplish with this code?

    -Prelude
    My best code is written with the delete key.

  6. #6
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Hello Prelude!

    What exactly was the book trying to accomplish with this code?
    It asks me if it can call that function Calculate or not? That's it!

    I was wondering that myself since I could not compile it without the rest of the code inside that function, missing undeclared variables, etc.. as you mentioned.

    Thanks for all your help!

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >It asks me if it can call that function Calculate or not? That's it!
    Oh, in that case no, not as written.

    -Prelude
    My best code is written with the delete key.

  8. #8
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Thumbs up Roger, Dodger that!

    again Thanks Prelude!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Function name basic question help
    By kenryuakuma in forum C++ Programming
    Replies: 7
    Last Post: 09-24-2008, 07:48 AM
  4. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM