-
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.
-
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?
}
-
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;
}
-
yeh, i didn't really read the question, just saw the code...always do that. BTW, why do I smell like Cherios?