With C/C++, a semicolon terminates a command or declaration. So take care where to use it.
With function definitions (implementations), there must be no semicolon:
void candidate_entry (char*name[]) ;
void candidate_entry (char*name[])
{
}
[EDIT]
Thanks to Richard about pointing to the fact the return type was missing in the posted code and in my initial solution. So there are to errors in one line of code.
[/EDIT]
A common mistake is also placing a semicolon at the end of a
for
statement:
for(j=0;j<TOWN;++j);
This terminates the loop and the next statement is not executed inside the loop. All modern compilers generate a warning in this case when using a high warning level (but the ancient Turbo-C++ might not do so).
With C++, local variables should be declared when used and not on top of the function as required for C. Doing so would have issued an error with modern compilers:
for(int j=0;j<TOWN;++j);
cout<<"Enter #Vote for Candidate"<<name[i]<<"in Town"<<j+1<<;
But again, this might not apply to the old Turbo-C++ compiler.
Some general tips:
- Ensure that the code is easily readable (e.g. by indenting).
- Select the highest compiler warning level.
- When an error or warning occurs read the message and try to understand it.
- Read the compiler documentation for the message or look it up in the web for more information.
- Inspect the code line where the error occured and the preceeding line(s). An error or warning is often sourced by a previous line and detected later.
- If you still got stuck you may ask a community like this one. But then include the full message and indicate the corresponding line in the posted code.