I'm trying to write a program in complex arithmatic for my math class. The text I have gives me the following for addition:

typedef struct FCOMPLEX {float r,i;} fcomplex;
fcomplex Cadd(fcomplex a, fcomplex b)
{
fcomplex c;
c.r=a.r+b.r;
c.i=a.i+b.i;
return c;
}

but my compiler refuses to accept it. it gives me the following:
non-local function `main()::fcomplex Cadd(main()::FCOMPLEX, main()::FCOMPLEX)' uses
and then proceeds to tell me that my variables are neither int, double, nor float.
I have iomanip, iostream, and cmath as my included libraries. One of my books doesn't even list complex arithmatic while the other only shows me the various code pieces. I can't figure out how to make the program do what I want it to do. Help?

Thanks!

Hard to tell from what you posted, but having 'main()::' in the error is awfully suspicious. Is CAdd and the FCOMPLEX definition OUTSIDE of main()? as in:

typedef ...
CAdd()...
{
}

int main( ...)
{
}

The only things outside the int main() part are the include libraries. I've tried to work through this problem since I posted this initially. If ound another website that gives me a little bit of information on the subject as well, but it doesn't seem to work either. it deals with a class complex.
Thanks though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.