Problem with pointers and function

this is for my computer programming class. I'm suppose to make a program that ask for how many grades the user would like to enter. then they would enter the grades. I was able to do it, but the teacher wants us to use pointers and function(not good at either).He also wanted the sort to be in ascending order, and to average the grades. I was able to get the program to compile however it just comes back as zeros.

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
55
56
57
58
59
60
#include <iostream>
using namespace std;

int GetSort(float *pter,int length);
int GetAvg(float *pter,int length);

int main()
{
    int a,i,length,sort,average;
    float *pter;
    pter = new float[length];

    cout<<"Enter the number of grades you like to input: ";
    cin>>length;

    for(i=0;i<length;i++)
    {
        cout<<"\n Enter grade: ";
        cin>>pter[length];

    }
    sort=GetSort(pter,length);
    average=GetAvg(pter,length);
    cout<<"The Grades entered are: "<<endl;
    for(a=0;a<length;a++)
        cout<<sort<<endl;
    cout<<"The Average for all grades are: "<<average<<endl;
    delete[] pter;
    pter=0;
    return 0;


}
int GetSort(float *pter,int length)
{
   int temp,p,q;
   for(p=0;p<length;p++)
   {
       for(q=length-1;q>=p;q--)
       {
           if(*(pter+p+1)>*(pter+p))
              {
                temp= *(pter+p);
                *(pter+p) = *(pter+p+1);
                *(pter+p+1)=temp;
              }
       }
   }
   return *pter;
}
int GetAvg(float *pter,int length)
{
    int total, r,sum=0;
    for(r=0;r<length;r++)
    {
        sum = sum += *pter;
        total= sum/length;
    }
    return total;
}


The way i was trying to program it was so that i have two functions. One for bubble sorting to ascending order, and the second to average the grades. Any suggestions would be greatly appreciated, also that any comments to let me know if i was going in the right direction would also be appreciated.
Gimenez Carlos, Contractor

_Morning my friend. We want a building.
GCC: ¿what kind of building will please you?
_ A building, you know. The kind that has walls.
GCC: ok, done.
_ Great, that was fast. I want you to meet the architect. So Mr. architect ¿how many floors do you want?
_ 42
GCC: the building is already constructed. It has 13 floors.
_ Now we need to paint it. Let's go to the 54 floor.
GCC: That would be difficult...
_ (not listening) ¿What colour do we choose?
_ Let's start with Red, next Green, Green and Green. Blue later. Draw a tiger here, a river and the treasure map.
Cover everything with black.
GCC: *sigh*
...
_ We'll pay you 10 times the cost of the first floor. But calculate it twice, just to be sure
_ Now the speech for the inauguration:
All work and no play makes Jack a dull boy.
All work and no play makes Jack a dull boy.
All work and no play makes Jack a dull boy.
...

And that's basically the story of your code.
Also your sort is obfuscated and you are accessing out of bounds.
Topic archived. No new replies allowed.