Array searching removing elements

Hello,

I am having trouble working with an array problem, searching and deleting ints.Any help would be very appreciated. Thank you very much!
Goals:
-array of ints with 30 elements
-int to (index +1) * 5 for first 20 elements
-Display result
-add 68, 2, 114, 111
-Display result
-remove 114,42,60,2
-Display result
-use binary search

Questions/Problems
1) I tried to create a loop such that it would index +1 and multiply by 5 for the first 20 elements but it did not output. What am I doing wrong?

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

using namespace std;

int main()
{
int array[30];
int i;

    
    
// Change 1st 20 elements to (index +1) * 5
for (i=0; i< 20; i++)
    {
        array[i]= (i+1)*5;
    }
    
// Display array 
for (i=0; i<30; i++)
    {
        cout << array[30] << " ";
    }
    
// Add

return 0;
}


2)I'm assuming for adding into the array based on those directions I had starting at position 20 like this?
[code
// add to array
array [20] = 68;
array [21] = 2;
array [22]= 114;
array [23]=111;


][/code]

3) How should i remove the values 114, 42, 60,2? Loop through for each value? is there a more efficient way?
1
2
3
4
5
6
7
for(i=0;i<30; i++)
{
    if(array[i] == 114)
        array[i] == 0; 

}
Last edited on
there are vectors...
and your display vector loop is wrong.
EDIT: http://www.cplusplus.com/reference/stl/vector/
Last edited on
Topic archived. No new replies allowed.