Thread: Function Error

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    3

    Lightbulb Function Error

    I need to pass 3 varibles from main to a function, then do some calculation, after that the function will return another 2 varibles back to main, then the main will continue to use the new varible to do difference calculation.

    example:

    main()
    {
    float a=5;
    float b=6;
    float c=7;
    function (a,b,c);
    ;
    p= e +2;
    ;
    }

    function (a,b,c)
    {
    d=a+c;
    e=b+b;
    }

    my problem is i can't bring the d & e value back to continue the main calculation, if possible please guide me the structure to develop the program, what kind of declaration and statement need to do? i try with array and pointer still not able.

  2. #2
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Code:
    main() wouldn't int main be better?
    {
        float a=5;
        float b=6;
        float c=7;
        function (a,b,c);
        ; // whats this  doing here??
        p= e +2; // where was p or e defined?
        ; // same here?
    }
    
    function (a,b,c) // wheres the return type?
    {
        d=a+c; // where was d defined?
        e=b+b; // where was e definined?
        // shouldn't this function return something?
    }

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    26
    Try the following:

    PHP Code:

    #include <stdio.h>
    void function (float,float,float ,float *,float *);
    int main()
    {

      
    float a=5;
      
    float b=6;
      
    float c=7;
      
    float sum;
      
    float sum2;
       
       function (
    a,b,c,&sum,&sum2);
       
    printf("%f%3f\n",sum,sum2);
       
    system("PAUSE");

     return 
    0;

    }

    void function (float a,float b,float c,float  *sum,float  *sum2)
    {
      *
    sum=a+c;
      *
    sum2=b+b;


  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    yeh, i didn't really read the question, just saw the code...always do that. BTW, why do I smell like Cherios?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM