trouble creating a *.h file

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
You need to add to the end of your header definition:

#endif


That might be why.

~psault
Last edited on
No.

The file doesn't have any errors, just won't compile AT ALL. Won't even try to compile.
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
TY.

Also, any way so that a BUNCH of numbers can be used in my aver() function?
You can use a dynamic argument list. In much the same way printf does it or main does it.

Google C++ dynamic argument list.
Don't get it. Dynamic Argument List = Greek to me.
Ty.

Wow, the board has changed a lot.
Wow, new problem. That link only covered void functions. What if I wanted to do function with a return value?
Last edited on
It's exactly the same, just with a different return type.

1
2
3
void something() { }

bool somethingelse() { return true; }
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?
Last edited on
Topic archived. No new replies allowed.