Arrays

I need help with the deleteArray function. How can I remove the "5" and shift the values left of the five to the right.
It should look like:
0 1 2 3 4 6 7 8 9 10
11 12 13 14 15 16 17 18 19



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
#include <iomanip>
#include <iostream>

using namespace std;

void printArray(int arr[],int len)
{
    for(int i = 0; i < len; i++)
    {
        if (i>0 && i % 10 == 0)
            cout<<endl;
        cout<<setw(2)<<arr[i]<<" ";
    }
    cout<<endl;
}
void deleteArray(int original[], int origLen, int newArray[], int index){

    for(int i = 0; i < origLen-1; i++){
        newArray[i] = original[i];
    int index = 0;
        }for(int x = 0; x < origLen-1; x++){
            newArray[index] = 0;
        }
}
void biggerArray(int original[], int origLen, int newArray[], int newLength){
    for(int i = 0; i < origLen; i++){
        newArray[i] = original[i];
    }
}

int main()
{   int intArray[20] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
    int smallArray[19] = {};
    int bigArray[25] = {};

    cout<<"Original array: "<<endl;
    printArray(intArray,20);
    cout<<endl;

    cout<<"Smaller array:  "<<endl;
    deleteArray(intArray,20,smallArray,5);
    printArray(smallArray,19);
    cout<<endl;

    cout<<"Bigger array:   "<<endl;
    biggerArray(intArray,20,bigArray,25);
    printArray(bigArray,25);
    cout<<endl;

    return 0;
}
Last edited on
delete this line
 
cout<<printArray<<endl;
Thank you! I changed it to cout<<endl; so i could maintain the space between the print statements but get rid of the '1'.
You are decrementing originlen. Change it to originlen -1
Topic archived. No new replies allowed.