Function data type conversion!!!

Does anyone know why when i compile, it will show this error- error C3861: 'doubleAdd': identifier not found
What should i do to get the output?


#include<stdio.h>

int main()
{
int x= 4.7, y=5.5;
int result=doubleAdd(x, y);
printf("%d", doubleAdd(x, y));
}

double doubleAdd (double x, double y)
{
return x+y;
}
Last edited on
You need to declare your function before you use it. C/C++ compilers aren't "smart" enough to look ahead in your program to find the function you want.

Read up on function prototypes, and include one in your program before main().

You're also passing ints to a function expecting doubles; I'm not sure how that's going to work out.
Oops! The value 4.7 and 5.5 are being assigned to int x and y. Those vars will only get 4 and 7 respectively.
Also, the returned value from doubleAdd() is being assigned to an integer
int result = d......
but doubleAdd() returns a double, it is the possible for result to be zero from trying to demote a double to an int. Printf is trying to print a double as a decimal %d when it should be a long float like this: %lf //thats a lowercase 'ell' and lowercase 'eff'

//TRY:

#include<stdio.h>

double doubleAdd (double x, double y); //function prototype, enables forward referencing

int main()
{
double x= 4.7, y=5.5;
double result=doubleAdd(x, y);
printf("%lf", doubleAdd(x, y));
return 0;
}

double doubleAdd (double x, double y)
{
return x+y;
}
Ok! Thanks!!
Topic archived. No new replies allowed.