Howdy, Stranger!

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

Categories

help with header files

rrrrr12345rrrrr12345 Member Posts: 56
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

  • gustavosserragustavosserra Member Posts: 201
    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

  • rrrrr12345rrrrr12345 Member Posts: 56
    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
    :
    :

  • gustavosserragustavosserra Member Posts: 201
    : 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!!

  • Shawn CarterShawn Carter Member Posts: 0

    _______ < http://forcoder.org /> free ebooks and video tutorials about | Swift, PL/SQL, Perl, MATLAB, C, Objective-C, Go, Java, Python, Scratch, Delphi, R, C#, Assembly, Visual Basic, JavaScript, Ruby, PHP, C++, Visual Basic .NET F#, Lua, Awk, Prolog, Clojure, Scheme, Apex, Lisp, FoxPro, Fortran, ML, Scala, SAS, D, Ada, Julia, Bash, Logo, ABAP, Erlang, VBScript, Hack, COBOL, LabVIEW, Kotlin, Dart, Crystal, Alice, Rust, Transact-SQL | ___

Sign In or Register to comment.