Weird compiling error.

So I hit the compile button and was waiting when I received this message.

e:\programs\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\libmingw32.a(main.o):main.c:(.text.startup+0xa7)||undefined reference to `WinMain@16'|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 14 seconds) ===|

This really confuses me I can't under stand what it is or why I'm getting this error. I found other people getting similar errors but couldn't understand why. So if anyone could explain it that would be helpful. Thanks,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>

int srand_0toN(int n);

int hits[10];


int mian()
{
    int n;
    int r;
    int i;

    srand(time(0));
    std::cout << "Enter a number of tirals to run and press ENTER: ";
    std::cin >> n;

        for(i = 0; i <= n; i++)
        {
           r = srand_0toN(10);
            hits[r]++;
        }
        for(i = 0; i < 10; i++)
        {
            std::cout << i << ": " << hits[i] << " Accuracy: ";
            std::cout << static_cast<double>(hits[i]) / (n/10) << std::endl;
        }
        return 0;
}

int srand_0toN(int n)
{
    return rand() % n;
}
undefined ref to main. You typo'd the main function

 
int mian()
if you're getting an undefined reference to WinMain@16, you probably selected the wrong type of project. You want a console project, not a Windows project.

BTW, main is mispselled on 11. This could also cause linker problems because the linker can't find your main function.



Thanks for the help I seem to have not noticed the slight misspelling. Sorry for being so forgetful about my code. I'm happy to say it's working wonderfully and your support is very helpful.
Topic archived. No new replies allowed.