Getting test scores using pointers

I'm trying to basically have a user input the amount of test they want averaged, then have the user input the test scores. Send the test scores to a function and have them ordered in ascending then send it to another function that averages it. When I wrote the function I keep getting the address back instead of the actual values, any help would be very appreciated!
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
#include <iostream>
#include <iomanip>
using namespace std;


void arrSelectSort( int* [], int);
void arrAverage(int);

int main()
{
	int* testScores;
	int SIZE;
	cout << "How many test will test will averaged? " ;
	cin >> SIZE;

	testScores = new int[SIZE];

	for (int count = 0; count < SIZE;count++)
	{
		cout << "Please enter test # " << count+1 << ": " << endl;
		cin >> testScores[count];
	}

	arrSelectSort(&testScores,SIZE);




	return 0;
}

void arrSelectSort(int *testarry[],int size)
{
	int *temp;
	for(int count = 0;count< (size - 1);count++)
	{
		if (testarry[count]>testarry[count + 1])
		{
			temp = testarry[count];
			*(testarry + count) = *(testarry + (count+1));
			*(testarry + (count + 1)) = temp;
		}
	}
	for (int count = 0;count<size; count++)
	{
		cout << " The grades in ascending order are \n" << testarry[count];
	}
}

Last edited on
1
2
3
4
5
6
if (count[*testarry] > count + 1[*testarry])
{
	*temp = (*testarry)[count];
	(*testarry)[count] = (*testarry)[count + 1];
	(*testarry)[count + 1] = *temp;
}


Or

1
2
3
4
5
6
#include <algorithm>

if (count[*testarry] > count + 1[*testarry])
{
	std::swap(count[*testarry], count + 1[*testarry]);
}
Last edited on
Thanks for your input, but the first code you post didn't work even after I tried to tweak it. The other I didn't try because we haven't gotten that far yet.
You're problem starts here:void arrSelectSort( int* [], int); This tells the compiler that the first argument is a pointer to a pointer which is why this only works if you pass 'testScores' (already a pointer) by reference. You are also missing an embedded for loop in your "arrSelectSort()" function, otherwise you're only making one pass and not sorting the array properly.
Last edited on
Topic archived. No new replies allowed.