compare values in a array

I making a program where 10 person input a number and then it output who has the highest number and what the number is. so far i made this



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
#include<string>
using namespace std;
main(){

string personlist[10][2] = {

{"person1", },
{"person2", },
{"person3", },
{"person4", },
{"person5", },
{"person6", },
{"person7", },
{"person8", },
{"person9", },
{"person10", }};

int count = 0;
while(count != 10){

cout << personlist [count][0] << " : ";
cin >> personlist[count][1];

++count;
}
I really think you need to look up some documentation for arrays. You don't need a multidimensional array to do this task. Also since you're using an array of strings you're not actually inputing numbers, your inputing strings.

http://www.cplusplus.com/doc/tutorial/arrays/
okay i tried something a little different and i apologize if im totaly lost

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<iostream>
#include<string>
using namespace std;
main(){

string personlist[10] = {

{"person1"},
{"person2"},
{"person3"},
{"person4"},
{"person5"},
{"person6"},
{"person7"},
{"person8"},
{"person9"},
{"person10"}};

int numberlist[10];


int count = 0;
while(count != 10){


cout << personlist [count] << " : ";
cin >> numberlist[count];

++count;
}

int holder = 0;
string holder2 = "persone1";


for (int o = 0 ; o < 10; o++){
for (int i = 0; i < 10 ; i++){
	if (numberlist[i] > numberlist[i + 1]){
		holder = numberlist[i + 1];
		numberlist[i] = numberlist[i + 1];
		numberlist [i + 1] = holder;
		
		holder2 = numberlist[i + 1];
		personlist[i] = personlist[i + 1];
		personlist [i + 1] = holder2;
		
	};};};

for (int p = 0; p < 10 ; ++p){
	cout << personlist[p] << " : " << numberlist[p]<< endl;
}

	return 0;
}
What is the purpose of the personlist array?

Why not just print this :
cout << "Person " << count << ": " ;

Also you may want to re-check your sort routine. It is accessing your arrays out of bounds. Plus your "swap" isn't correct.

its purpose is each person input a number and then it sort the list and output which person have the highst number.
Why not find the highest number before you sort the numbers? If you really think you must keep track of both the person and the score I recommend you use a structure that contains this information, not parallel arrays.
okay i found a way thanks for the help :D
Topic archived. No new replies allowed.