2D array find sum

I want to find the highest scored player and print it.Can anyone explain the logic that i can use in
int Findwinner(int data[][4],int rowSize,int colSize)
thanks..

#include<iostream>
using namespace std;
void inputdata(int data[][4],int rowSize,int colSize);
int Findwinner(int data[][4],int rowSize,int colSize);

int main()
{
int tbl[3][4];
inputdata(tbl,3,4);
Findwinner(tbl,3,4);
return 0;
}


void inputdata(int data[][4],int rowSize,int colSize)
{
for(int a=0;a<colSize;a++)
{
cout<<"Round "<<a+1<<endl;
for(int b=0;b<rowSize;b++)
{
cout<<"Enter score of player 100"<<b+1<<":"<<endl;
cin>>data[b][a];
}
}
}


int Findwinner(int data[][4],int rowSize,int colSize)
{
int sum;
for(int a=0;a<colSize;a++)
{
sum=0;
for(int b=0;b<rowSize;b++)
{

sum=sum+data[b][a];
}
cout<<"Sum"<<sum<<endl;

}
}
Since you haven't explained the rules for determining a winner or the organization of tbl, it's difficult to make suggestions.

Why is tbl a 2d array?

Assuming one dimension represents players, what does the other dimension represent?

What's the purpose of sum in Findwinner? Is the winner the player with the highest sum?

Findwinner doesn't currently do anything other than printing the sum of each row.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
Actually i want to get average of each player and print only the winner..
there are 4 rounds for each player..
yes here i am geeting only the sum of each player ,i can get average just dividing by 4.
my question is how can i get the highest average ?
sorry about my English..
thanks..
How would you find the maximum value from a 1D array?
The sums are a logical 1D array.
Topic archived. No new replies allowed.