Jan 24, 2014 at 10:01am UTC
I need help with the counter. I am trying to count how many people are friends with the person. I'm not sure where I can put it to get the right results.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void friendData(int numP, char names[][4], int table[][MAX_PEOPLE])
{
int counter = 0;
for (int i = 0; i < numP; i++)
{
cout << names[i] << " (" << counter << "): " ;
counter = 0;
for (int k = 0; k < numP; k++)
{
if (table[i][k] == 1)
{
counter++;
cout << names[k] << " " ;
}
}
cout << endl;
}
}
output
Ami (0): Leo Sue
Ann (2): Luc Meg
Ben (2): Dan Luc
Ema (2):
Ira (0): Guy
and so on.
desired output
Ami (2): Leo Sue
Ann (2): Luc Meg
Ben (2): Dan Luc
Dan (0):
Luc (1): Leo
Last edited on Jan 25, 2014 at 7:21am UTC
Jan 24, 2014 at 10:34am UTC
Try putting the counter on line 6, and initializing it to zero then (start the counter again for each person).
Jan 25, 2014 at 7:22am UTC
so I was able to reset it everytime but i need to shift the counter up one