Issue with pointer function

Hello all!!

I'm pretty much new to pointers and function. Yes this an assignment, but i just want to know if I'm going in the right direction. Any comments is greatly 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
#include <iostream>
using namespace std;

int BubSort(int *,int i)


int main()
{
    int p, i,sort,avg;
    int *pter;


    cout<<"Enter how many grades you want to enter: ";
    cin>>i;
    pter= new pter[i];

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

    cout<<"Grades are: "<<sort<<endl;
    delet
}

float BubeSort(float *pter, float i)
{   float a,b,temp;
    for(a=0;a<i;a++)
    {
        for(b=i-1;b>=a;b--)
        {
            if(*(pter-1)<*pter)
            temp=*(pter-1);
            *(pter-1)=*pter;
            *pter=temp;
        }
    }
    return *pter;
}


the error I'm getting is expected initializer before 'int'
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
#include <iostream>
using namespace std;

int BubSort(int *,int i); // You needed a semi-colon here


int main()
{
    int p, i,sort; // avg is not required
    int *pter;


    cout<<"Enter how many grades you want to enter: ";
    cin>>i;
    pter= new int[i]; //You need to make this an array of ints, not pter

    for(p=0;p<i;p++)
    {
        cout<<"\n Enter grade: ";
        cin>>pter[p];
    }
    sort=BubSort(pter, i); // You need to put arguments in here, Bubsort should be BubSort

    cout<<"Grades are: "<<sort<<endl;
    delete pter; // You spelled delete wrong, you also need to specify the object to delete.
}

int BubeSort(int *pter, int i) // Should be int, not float
{   int a,b,temp; //should be ints
    for(a=0;a<i;a++)
    {
        for(b=i-1;b>=a;b--)
        {
            if(*(pter-1)<*pter)
            temp=*(pter-1);
            *(pter-1)=*pter;
            *pter=temp;
        }
    }
    return *pter;
}
Thank you soo much!!! you can tell i'm new to this lol
Topic archived. No new replies allowed.