0

Hi ,i am so happy that you guys help me out for my previous problem concerning about coding programming.Right now i am stuck with my Candidate programme where i need to Cout the total result for the winning candidate.

The question is : There is 5 candiate runing for little city where the population is 2000 people.I allready write the programme but i dont how to Cout the final result for the winning candidate .SO please can you help me out

#include <iostream>
using namespace std;
int main ()
{

	const int candidatenumber=5;
	const int votenumber=10;

	int candidate[candidatenumber]={0};
	int vote[votenumber];

	for(int i=0;i<votenumber;i++)
	{
		cout<<"Enter your vote 1 to 5 :"<<endl;
		cin>>vote[i];
		candidate[vote[i]]++;
	}


	return 0;
}
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by vmanes
0

If your problem is to display the number of votes each candidate got, you'll use a loop similar to your input loop, only output each element of the candidate array. If you want to only show which candidate won (got the most votes), you'll have to go through the candidate array keeping track of the index that holds the largest value.

Food for thought: What do you do in case of a tie?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.