Saturday, May 22, 2010

C++ code errors?

I recieve the following errors when I attempt to compile my program, please help.








pim.cpp: In function `void searchContacts(...)':


pim.cpp:112: `count' undeclared (first use this function)


pim.cpp:112: (Each undeclared identifier is reported only once


pim.cpp:112: for each function it appears in.)


pim.cpp:114: `contacts' undeclared (first use this function)


pim.cpp:114: parse error before `||'


pim.cpp:118: warning: implicit declaration of function `int print(...)'


pim.cpp:120: confused by earlier errors, bailing out








void searchContacts(PIM pim.contacts[], int count)


{


int matches = 0;


string name;


cout %26lt;%26lt; "\nEnter first or last name to find: ";


cin %26gt;%26gt; name;


for (int i = 0; i %26lt; count; i++)


{


if (contacts[i].firstname == name) || contacts[i].lastname == name))


{


matches++;


cout %26lt;%26lt; "\nContact " %26lt;%26lt; (i + 1) %26lt;%26lt; ":" %26lt;%26lt; endl;


print(contacts[i]);


}


}


cout %26lt;%26lt; "\nTotal number of matching contacts: " %26lt;%26lt; matches %26lt;%26lt; endl;


}

C++ code errors?
I can help you out, just name the compiler and version (gcc or microsoft c++)
Reply:for (int i = 0; i %26lt; count; i++)





you need to declare count:





const int count=10; or something like that





if (contacts[i].firstname == name





the array contacts is unknown, because your function declaration is broken. use:


void searchContacts (PIM contacts[]...)


or


void searchContacts (PIM *contacts...)





print (contacts[i])





The print function is unknown. You need a function declaration BEFORE searchContacts or in a header file.


No comments:

Post a Comment