Click here to Skip to main content
15,885,810 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#define NUM_CANDIDATE 3
#define TOWN 3

int votes[NUM_CANDIDATE][TOWN];
candidate_entry (char*name[]) ;
{int i,j;
for(i=0;i<=NUM_CANDIDATE;++i)
{cout<<"Enter name of Candidate No."<<i+1;
cin>>name[i];
for(j=0;j<TOWN;++j);
cout<<"Enter #Vote for Candidate"<<name[i]<<"in Town"<<j+1<<;
cin>>votes[i][j];
}
}
 show_total_votes(char*name[])
{int total;
cout<< "Name     Town\n";
cout<< "of Candidate     1     2     3\n";
cout<<"Total\n<<" ;

cout<< "================================<<\n";
for(i=0;i<=NUM_CANDIDATE;++i)
{total=0;
cout<<"name[i]"<<name[i];
for(j=0;j<=TOWN;++j)
{total+=votes[i][j];
cout<<"total"<<total;
}
}
int main()
{char name[NUM_CANDIDATE][NAME_LEN];
int i;

char*name_pt[NUM_CANDIDATE];

clrscr();
for(i=0;i<NUM_CANDIDATE-1;++1)
name_pt[i]=name[i];

candidate_entry(name_pt);
show_total_votes(name_pt);
	       }
getch();
return(0);
}


What I have tried:

C++
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#define NUM_CANDIDATE 3
#define TOWN 3

int votes[NUM_CANDIDATE][TOWN];
candidate_entry (char*name[]) ;
{int i,j;
for(i=0;i<=NUM_CANDIDATE;++i)
{cout<<"Enter name of Candidate No."<<i+1;
cin>>name[i];
for(j=0;j<TOWN;++j);
cout<<"Enter #Vote for Candidate"<<name[i]<<"in Town"<<j+1<<;
cin>>votes[i][j];
}
}
 show_total_votes(char*name[])
{int total;
cout<< "Name     Town\n";
cout<< "of Candidate     1     2     3\n";
cout<<"Total\n<<" ;

cout<< "================================<<\n";
for(i=0;i<=NUM_CANDIDATE;++i)
{total=0;
cout<<"name[i]"<<name[i];
for(j=0;j<=TOWN;++j)
{total+=votes[i][j];
cout<<"total"<<total;
}
}
int main()
{char name[NUM_CANDIDATE][NAME_LEN];
int i;

char*name_pt[NUM_CANDIDATE];

clrscr();
for(i=0;i<NUM_CANDIDATE-1;++1)
name_pt[i]=name[i];

candidate_entry(name_pt);
show_total_votes(name_pt);
	       }
getch();
return(0);
}
Posted
Updated 24-Nov-16 21:23pm
Comments
Dave Kreskowiak 24-Nov-16 23:24pm    
Did you want to describe what the problem is or should everyone just take a wild guess?
Member 12869596 25-Nov-16 0:30am    
When I compile that using TurboC++, Line 9 shows "Declaration Terminated Incorrectly" error.
Member 12869596 25-Nov-16 0:31am    
or rather the line 8 ({int i'j;) part
Philippe Mori 25-Nov-16 10:28am    
Why writing the same code twice? Why not properly indent it? And why not explaining the problem?

It's not in a function declaration:
C++
int votes[NUM_CANDIDATE][TOWN];
candidate_entry (char*name[]) ;
    {
    int i,j;
    for(i=0;i<=NUM_CANDIDATE;++i)
        {
        cout<<"Enter name of Candidate No."<<i+1;&lt;!-- newline="" --="">        cin>>name[i];

I'm guessing that what you meant to say was:
C++
int votes[NUM_CANDIDATE][TOWN];
void candidate_entry (char*name[])
    {
    int i,j;
    for(i=0;i<=NUM_CANDIDATE;++i)
        {
        cout<<"Enter name of Candidate No."<<i+1;&lt;!-- newline="" --="">        cin>>name[i];

That won't fix all the problems (your main function is well screwed up as well) but it'll fix that one.

And please, indent your code! It makes it a whole load easier to spot problems like this...
 
Share this answer
 
v2
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:
// Function declaration:
void candidate_entry (char*name[]) ;

// Function definition (implementation):
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);
// Compiler throws an error here about unknown variable j
//  because j is out of scope now
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.
 
Share this answer
 
v2
Comments
Richard MacCutchan 25-Nov-16 3:32am    
Missing return type.
Jochen Arndt 25-Nov-16 3:37am    
Off course!
Was sipping on my first coffee while posting. Should have one more.

Would not have happened if error messages has been posted.

Thank you Richard.
I will update my solution.
Richard MacCutchan 25-Nov-16 3:58am    
I'm on my first cup of tea, so that must be the answer. Most days I would not have noticed.
You should try
C++
candidate_entry (char*name[])
{
int i,j;


And the return type is missing.
 
Share this answer
 
v2
Comments
Richard MacCutchan 25-Nov-16 3:33am    
Missing return type.
Patrice T 25-Nov-16 3:47am    
Of course, I was focused on the semi column.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900