1 2 3 4 5
|
if(n<0 || n>MAX)
{
cout<<"There aren't more then 23 players on a rugby team!"<<endl;
return -1;
}
| |
first, you have a magic 23 in your text; it should be cout << "words" << MAX << "morewords" but that is irrelevant. Also, this logic will say that you have more than max if you put in -3 for input. That seems odd. Also, its than, not then.
all that aside, I believe you want a struct.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
struct namescore
{
int score;
string name;
};
namescore arr[max];
for(i=0;i<n;i++)
{
cout<<"Enter score: ["<<i+1<<"] ";
cin>>arr[i].score;
cout<<"Enter name: ["<<i+1<<"] ";
cin>>arr[i].name;
}
| |
and so on. everywhere you had arr before, you now need arr[index].field so your sort and so on all need to do it that way. be SURE that your swap in the sort moves BOTH fields, not just the score... ideally you would add an assignment operator (and, I always mess this up, but it may actually generate one for you for this simple struct, sometimes it can do that) so that you don't have to touch each field to copy (like in your swap statements).
I have no idea what you wanted a pointer for. I can use one, if you want one just to have it, but you don't need one. You could make arr dynamic:
namescore * arr;
arr = new namescore[n]; //can be a variable now, unlike array needed max
...
and when done
delete[] arr;