help me compare 3 or more arrays

well i have this project which i need to create a lot of user defined array say:
int num;
int array[num];
and it goes on and on like that. say:
string array1[num];
int array2[num];
int array3[num];

now I'm thinking of comparing array2 and array3 together and since it will hold the same value with array1 and array, i want to output the largest in array2 and array3 and output the corresponding value in array1. for example:

array2[num]={6,10,7}
array3[num]={20,50,30}
array1[num]={bright,stanley,bridget}

cout<<"the winner is"<<stanley<<50<<10;

please help me achieve these goal
closed account (48T7M4Gy)
So, would it be correct to say 50 in array3 is the winning score?
judging from the example. yes. but i want to try it with a user-defined array which means the length of the array can change anytime
It sounds like you need an array of structs:
1
2
3
4
5
6
7
8
9
class Info {
public:
string name;
int value2,value3;
};

Info arr[num];
...
cout << "the winner is " << arr[winner].name << arr[winner].value2 << arr[winner].value3
Last edited on
closed account (48T7M4Gy)
This appears to be a simple case of parallel arrays. The length of the array(s) would not be significant while maintaining sync between arrays would be.

All that is necessary is to determine the index of the maximum value in the array and that index is used to select the corresponding elements with the same index from the other arrays.

As it turns out the OP's vagueness on which array(s) constitute the source(s) for the maximum doesn't matter. That is determined by the rules for scoring which OP doesn't know by the look of it.

So, that rule could be for all we know the number of letters in the name or the sum of elements in two arrays or whatever.

The assumption of synchronous parallel arrays is mine and might not have anything to do with this open-ended question. struct's certainly assist synchronous behaviour.

Cheers ;)


Last edited on
I'll try that. Thanks all.
Topic archived. No new replies allowed.