Pls help [urgent]

hi all,

i cannot success the program

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

// Program 6.5
#include <iostream>
using namespace std;

int CarianPduaan (int a[ ], int n, int target)
{ int first=0;
int last=n-1;
int mid;
while (first <= last)
{ mid = (first + last) /2;
if(target== a[mid])
return mid;
else if(target< a[mid])
{
last=mid -1;
cout<<"nilai tengah:"<<mid<<"\tmula:"<<first<<"\takhir:"<<last<<endl;
}
else
{
first=mid +1;
cout<<"nilai tengah:"<<mid<<"\tmula:"<<first<<"\takhir:"<<last<<endl;
}
}
return -1;
}
You're missing a main function - that's the entry point to the program.

If you can use code tags, it makes your code easier to read. It's the <> button in the format palette at the right side of the post.

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
#include <iostream>
using namespace std;

int CarianPduaan (int a[ ], int n, int target)
{ 
    int first=0;
    int last=n-1;
    int mid;
    while (first <= last)
    { 
        mid = (first + last) /2;
        if(target== a[mid])
            return mid;
        else if(target< a[mid])
        {
            last=mid -1;
            cout<<"nilai tengah:"<<mid<<"\tmula:"<<first<<"\takhir:"<<last<<endl;
        }
        else
        {
            first=mid +1;
            cout<<"nilai tengah:"<<mid<<"\tmula:"<<first<<"\takhir:"<<last<<endl;
        }
    }
    return -1;
}
can you give me an example?
There's a simple example here in the tutorial on the structure of a C++ program.

http://www.cplusplus.com/doc/tutorial/program_structure/
Topic archived. No new replies allowed.