I have to calculate the total of scores the participants received from the judges. And the one who gets the highest score will be the winner. I have to display the name of the winner but it displays the wrong winner. how do I solve this?
int main(){
int scores[5][2], i, j; int sum =0;
string name [5];
for(int i=0;i<5;i++)
{
cout << "Enter participant's name: \n";
cin >> name[i];
cout<<"Enter scores for " << name[i] <<endl;
for(j=0;j<2;j++)
{
cin >> scores[i][j];
}
}
for(int i=0; i<5; i++)
{
sum = 0;
for(j=0; j<2; j++)
{
sum += scores[i][j];
}
cout<<"Total scores of " << name[i] << " " <<" is "<<sum<<endl;
}
int max, min, count;
int index[5];
max = min, count=0;
index[5]={0};
for(int i=0; i<5; i++)
{
for(j=0; j<2; j++)
{
if (scores[i][j]>max)
{
max=scores[i][j];
}
}
for(int i=0; i<5; i++)
{
if(scores[i][j]==max)
{
index[count]=scores[i][j];
count++;
}
}
if (count==1)
cout<<"The winner is " << index[count-1] << name[i] << endl;
}
return 0;
}