Passing arrays to functions. Why won't this work!?


/* By: Jacob */

#include <iostream>
using namespace std;

int descend(int *, int, int);
int main ()
{
int num[10];
int awn =1;
int x=0,i=0,t=0, a, b, c, size=10, z=0;
char numawn='y';

do{ // Load integer array
cout << "Please enter a integer number:" << endl;
cin >> num[x];
x++;
cout << "Would you like to enter another integer?" << endl << "y for yes n for no:" << endl;
cin >> numawn;
}while(numawn=='y');

for(t;t<x;t++) cout << num[t] << " "; //display integer array

descend(num,x,t);


for(t=0;t<x;t++) cout << num[t] << " " << endl;; //display integer array

//bubble sort descending
for(a=1; a<x; a++)
for(b=x-1; b>=a; b--) {
if(num[b-1] < num[b]) {
c = num[b-1];
num[b-1] = num[b];
num[b] = c;
}
}

for(t=0;t<x;t++) cout << num[t] << " " << endl; //display integer array


return 0;
}

int desend(int *num, int t, int x){
//bubble sort ascending
int a, b, c;
for(a=1; a<x; a++)
for(b=x-1; b>=a; b--) {
if(num[b-1] > num[b]) {
c = num[b-1];
num[b-1] = num[b];
num[b] = c;
}
}
return *num;
}

im trying to turn this bubble sort into a function that I can just call when I need it. Please help me.
Last edited on
What problem are you having?
When I try to compile the program it shows errors. I think it is because I am incorrectly passing the variables and array.
When you post code, surround it with [code][/code] tags so it's easier to read.

What are the errors? Can't help you much without knowing what they are.
Well let me ask you this, how would you turn that bubble sort code into a function and what would the prototype be?
Topic archived. No new replies allowed.