Jun 24, 2008 at 1:34pm UTC
1 2 3 4 5 6
#ifndef AVG_H_
#define AVG_H_
float aver(float a1st, float a2nd, float a3rd){
return (a1st + a2nd + a3rd)/3;
}
For some reason, the file refuses to compile. Any ideas?
Last edited on Jun 24, 2008 at 5:58pm UTC
Jun 24, 2008 at 1:39pm UTC
You need to add to the end of your header definition:
#endif
That might be why.
~psault
Last edited on Jun 24, 2008 at 1:44pm UTC
Jun 24, 2008 at 3:16pm UTC
No.
The file doesn't have any errors, just won't compile AT ALL. Won't even try to compile.
Jun 24, 2008 at 5:40pm UTC
When you create a .h file, then you have a program that depends on it, you need to have the .h file available to your program (probably in the same directory as your .cpp file) and include it like:
#include "avg.h"
Of course you need to save that file as avg.h
Try compiling the .cpp code that depends on that header file after you do that.
~psault
Jun 24, 2008 at 5:56pm UTC
TY.
Also, any way so that a BUNCH of numbers can be used in my aver() function?
Jun 24, 2008 at 7:02pm UTC
You can use a dynamic argument list. In much the same way printf does it or main does it.
Google C++ dynamic argument list.
Jun 24, 2008 at 7:34pm UTC
Don't get it. Dynamic Argument List = Greek to me.
Jul 2, 2008 at 12:22am UTC
Ty.
Wow, the board has changed a lot.
Jul 2, 2008 at 12:28am UTC
Wow, new problem. That link only covered void
functions. What if I wanted to do function with a return value?
Last edited on Jul 2, 2008 at 11:51am UTC
Jul 2, 2008 at 7:04pm UTC
Aye, but say I wanted to return the sum of the arguments / number of arguments.
How can I make the program know how many arguments?
Jul 2, 2008 at 7:30pm UTC
Last edited on Jul 2, 2008 at 7:31pm UTC