help with header files

Hi all,


I am using the Dev C++ software for programming C++. I don't know how to link the header file to my main program. Currently, I have 3 files in the same directory: Main, average.h, average.cpp. The program gives me a message [Linker error] undefined reference to 'WinMain@16' in average.cpp when I compiled, and gives me [Linker error] undefined reference to 'average(int, int)' in main.cpp. How can this be solved?

Thanks in advance,
Roger


Average.cpp :
// #include
// #include"averages.h"

using namespace std;

/* FUNCTION TO COMPUTE INTEGER AVERAGE OF 3 INTEGERS: */
int average(int first_number, int second_number, int third_number)
{
return ((first_number + second_number + third_number) / 3);
}
/* END OF FUNCTION */

/* FUNCTION TO COMPUTE INTEGER AVERAGE OF 2 INTEGERS: */
int average(int first_number, int second_number)
{
return ((first_number + second_number) / 2);
}
/* END OF FUNCTION */



Average.h :
#ifndef AVERAGES_H
#define AVERAGES_H

/* (constant and type definitions could go here) */

/* FUNCTION TO COMPUTE INTEGER AVERAGE OF 3 INTEGERS: */
int average(int first_number, int second_number, int third_number);

/* FUNCTION TO COMPUTE INTEGER AVERAGE OF 2 INTEGERS: */
int average(int first_number, int second_number);

#endif


Main.cpp:
#include
#include"averages.h"

using namespace std;

int main()
{
int number_A = 5, number_B = 3, number_C = 10;

cout << "The integer average of " << number_A << " and ";
cout << number_B << " is ";
cout << average(number_A, number_B) << ".

";

cout << "The integer average of " << number_A << ", ";
cout << number_B << " and " << number_C << " is ";
cout << average(number_A, number_B, number_C) << ".
";

return 0;


Comments

  • I'm a C begginer, but I think I can help you...

    : Average.cpp :
    : // #include
    : // #include"averages.h"
    You must remove these //
    :
    :
    : Average.h :

    :
    : Main.cpp:
    : #include
    : #include"averages.h"
    Look at this include, isn't average.h instead of averageS.h?

    Hope that helps

  • Thank you for spotting the error, however, they are because of my typo mistake here, but actual error still occurs. Can anybody help?

    Roger


    : I'm a C begginer, but I think I can help you...
    :
    : : Average.cpp :
    : : // #include
    : : // #include"averages.h"
    : You must remove these //
    : :
    : :
    : : Average.h :
    :
    : :
    : : Main.cpp:
    : : #include
    : : #include"averages.h"
    : Look at this include, isn't average.h instead of averageS.h?
    :
    : Hope that helps
    :
    :

  • : Thank you for spotting the error, however, they are because of my typo mistake here, but actual error still occurs. Can anybody help?
    Have you removed the // in average.cpp? Send me all the code again,...
    Just a note: Dev C++? Argh!!! I do not like it!!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories