here is the simple code:

#include <allegro.h>
#include <iostream>
using namespace std;

int FindArea(int,int);

int main(){
     int lenghtOfYard;
     int widthOfYard;
     int areaOfYard;
     
     cout << "\nHow wide is your yard? ";
     cin >> widthOfYard;
     cout << "\nHow lond is your yard? ";
     cin >> lenghtOfYard;
     areaOfYard= FindArea(lenghtOfYard,widthOfYard);
     cout << "\nYour yard is ";
     cout << areaOfYard;
     cout << " square feet.\n\n";
     return 0;
}
int FindArea(int l,int w){
    return l*w;
}

and it gives me this error:

[Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status

what am I doing wrong? I got this from a book on c++, but it is kinda outdated. :icon_neutral:

Remove this line from your code (if you don't make use of the Allegro library): #include <allegro.h> Or if you're using Allegro:
If I'm not wrong each Allegro program looks like:

#include <allegro.h>

int main()
{
     allegro_init();
     /* more stuff goes here */
     return 0;
}
[B]END_OF_MAIN()[/B]

So you'll have to add the END_OF_MAIN() line, be sure you link the library as well.

should I put that on line 25 of my code or right after mian ends?

>>[Linker error] undefined reference to `WinMain@16'

You created the wrong kind of project -- create a new console project then copy/paste that program into it.

>>should I put that on line 25 of my code or right after mian ends?
Exactly as shown. Read the allegro tutorials here

what are the advantages and dis advatages between windows and console files?

what are the advantages and dis advatages between windows and console files?

A Windows project allows you to write GUI program (tutorial), such as one which you see when you run Notepad.exe. cout does not work with Windows programs, and requires WinMain() instead of main().

A console program has int main() and when run it normally opens up a console window. I think allegro programs require console programs.

quick question:
for console programs, should functions outside of main be infront of the main or behind, or does it not matter?(an example had them all before the main.)
Thanks for all the help so far!!!

It doesn't matter. If the functions follow main() then you have to declare the function prototypes before they are called. In really small programs I like to put main() at the bottom so that I don't have to mess with creating the prototypes.

so now i have some code. It gives me all these linker errors. What am I doing wrong?

#include <allegro.h>
int SCREEN_WIDTH;
int SCREEN_HEIGHT;
BITMAP *buffer;
int main(int argc, char *argv[]){
     allegro_init();
     install_mouse();
     set_gfx_mode( GFX_AUTODETECT_WINDOWED, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
     show_mouse(screen);
     SCREEN_WIDTH = 620;
     SCREEN_HEIGHT = 240;
     buffer = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT); 
}
END_OF_MAIN()

Also, on a side note, do I need to use header files for functions, or just for classes?

problem solved, had to link liballeg.a to project.
thanks for all the help, I will be back soon with more questions.
:)

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.