### problem with the function printarray

hey guys,
i wrote this code and i am having trouble with the function printarray. everything else is working fine i guess. please help ASAP! thank you :).
here is the code :
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113`` ``````#include #include using namespace std; void sortarray(double B[], int s){ int j=0; double temp=0.0; while (j>n; cout<<"please enter the size of the array of ordinates"<>m; x = new double [n]; y = new double [m]; randomVariables (x, n, 101, 0); randomVariables (y, m,101, 0); sortarray(x,n); sortarray(y,m); x = new double [n+n-2]; y = new double [m+n-2]; sortarray (x, (n+n-2)); printarray (x ,n); cout<<'\n'; printarray (y ,m); cout<<'\n'; printarray (x, (n+n-2)); cout<<'\n'; printarray (y, (m+n-2)); cout<<'\n'; delete x; x = NULL; delete y; y = NULL; delete x; x=NULL; delete y; y=NULL; return 0; }``````
First of all never use this stupid style of placing braces

void printarray (double * A, int K){

You can write the function the following way

 ``1234`` ``````void printarray ( const double * A, int K ) { for ( int i = 0; i < K; i++ ) cout << A[i] << ' '; }``````

Or if you want to use the pointer arithmetic then you can write

 ``1234`` ``````void printarray ( const double * A, int K ) { for ( const double *p = A; p != A + K; ++p ) cout << *p << ' '; }``````

Last edited on
it is printing but it is printing weird values that are not in the arrays
shit!! i think i figured out where the problem is. it starts from lines 83. i have to expand the size of the array then add elements to the array and sort them. can you help me? thanks a lot
Topic archived. No new replies allowed.