Help with copying and sorting arrays.

Been working on this for the past couple hours and still can't seem to figure it out. Posted the code below was wondering if someone can give me a direction in which to look at what to fix.


#include <iostream>

using namespace std;

void input (double x[],int length);
void copy (double data[],int length);
void sort (double x[],int length);
void display (double x[],double data[],int length);
int main()
{
double x[20];
int length;
double data[20];
cout << "Enter data item count <1-20>: " << endl;
cin >> length;

if (length < 1|| length > 20)
{
cout << "Item count is NOT within required range. Required range is 1 to 20" << endl;
}
input (x,length);
display (x,data,length);
copy (data, length);
sort (data, length);
display (data, x, length);

return 0;
}

void input (double x[],int length)
{
int i;
for (i=0;i<length;i++)
{
cout << "Enter Score: " << endl;
cin >> x[i];

}
}
void copy (double data[],double x[],int length)
{
for (int i=0; i<length; i++)
{
data[i] = x[i];

}

}
void sort (double data[],int length)
{
bool swapDone = true;
while (swapDone == true)
{
swapDone=false;
int temp;
for (int i=0;i<length-1;i++)
{
if (data[i] > data[i+1])
{
swapDone = true;
temp = data[i];
data[i]=data[i+1];
data[i+1] = temp;
}
}
}
}

void display (double x[],double data[],int length)
{

cout << "Orginal Data: " << endl;
for (int i=0;i<length;i++)
{
cout << x[i] << " ";
}
cout << endl;
cout << "Sorted Data: " << endl;
cout << data[i] << " ";

}
What are you asking? What errors are you getting? Where is it going wrong?
Sorry bout that. I'm getting the error "if you use -fpermissive G++ will accept your code" and it won't compile
I do see that your function definition of 'copy' has 3 parameters while the prototype only has 2. Check that and see if it helps.
Ok looks like now I just get that same compiler error when trying to cout the sorted array by couting data[i].
Probably because you need a separate for loop for the data array, your variable i is greater than length when you try to print the value of data[i] in your display function. Try that and hopefully it solves the problem.
Topic archived. No new replies allowed.