Please someone help me out with this one.compiler is asking for a primary expression before int.i am using DEV-C++ version 5.11

Oct 4, 2015 at 3:21pm
int main ()
{
int audience[100][2];
int i,N;
int index1=0,index2=0;
int comp_result;
cout<<"Enter the value of N : ";
cin >> N; // Enter size of the table
cout<<"Enter the base and exponent for " << N << "rows " << endl;

for(i=0;i<N;i++){

cin >> audience[i][0] >> audience[i][1]; //Enter numbers in the table

cout << endl << "Checking Function 1: Compare ecodes for 5 index pairs" << endl;


cout <<"\nEnter indices of row1 and row2 that you want to compare: ";
cin >> index1 >> index2;
if (index1 < 0 || index2 <0 || index1 >=N || index2 >=N)
continue;

int comparator(int audience[100][2],int index1,int index2);
{

int ecode[2],i;
for(i=0;i<3;i++)
{
ecode[1]=(audience[index1][0]^audience[index1][1])% 100;
ecode[2]=(audience[index2][0]^audience[index2][1])% 100;
}
if (ecode[1]==ecode[2])
comp_result ==0;

if(ecode[1]>ecode[2])
comp_result == -1;
if(ecode[1]<ecode[2])
comp_result == 1;
}
comp_result = int comparator(audience,index1,index2); //asking for primary expression before int

if(comp_result==-1)
{
cout << "ecode of index 1 is greater than ecode of index2" <<endl;}
else if(comp_result==1)
{
cout << "ecode of index 1 is less than ecode of index2" <<endl;}
else if(comp_result==0)
{
cout << "ecode of index 1 is equal to ecode of index2" <<endl;}

}
}
Last edited on Oct 4, 2015 at 3:58pm
Oct 4, 2015 at 4:00pm
If you intend to call a function there, then drop the `int'
comp_result = comparator(audience,index1,index2);


Also comp_result ==0; is doing nothing, if you want assignment use `='
comp_result=0;
Oct 4, 2015 at 4:07pm
After removing 'int' it is giving the following error
"C:\TurboC++\Disk\TurboC3\BIN\collect2.exe [Error] ld returned 1 exit status".
Oct 4, 2015 at 4:15pm
That's not the full error message.
I'll guess that it says something like "undefined reference" or "unresolved external".
¿have you coded a body for that function?
http://www.cplusplus.com/forum/general/113904/

Also, I thought that you were using Dev-C++, not Turbo-C++ ¿?
Oct 4, 2015 at 6:33pm
yeah ,you are correct.
now when i look at it, it does say something like "undefined reference".

Eventually I've also discovered that in the following part if we put "return 0 or 1 or -1",this error goes----but then program execution is not right.What should i do next please guide me.

if (ecode[1]=ecode[2])
comp_result =0;

if(ecode[1]>ecode[2])
comp_result = -1;
if(ecode[1]<ecode[2])
comp_result = 1;

Also though I am using DEV-C++ ,title bar is showing c:\Turbo C++\Disk\TurboC3\BIN\part.cpp-Dev-C++-5.11.I think its the same problem as linking and whatever(frankly i didn't get the term) for i also have TurboC++ on my system.How do we resolve this.Please help.

THANK YOU
REGARDS
Last edited on Oct 4, 2015 at 6:34pm
Oct 4, 2015 at 7:17pm
closed account (48T7M4Gy)
It looks like that fixed it. They are always something simple. Will there be anything else?
Topic archived. No new replies allowed.