Remove number from array

I have a code that chooses 5 numbers out of 10. How do I make it so that when I input something it removes that digit in the array?

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
#include <iostream>
#include <unistd.h>
#include <fstream>
#include <time.h>
#include <conio.h>
#include <windows.h>
#include <stdio.h>
#include <dos.h>
#include <thread>
#include<chrono>
#include<process.h>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
    int suggestion[] = {1,2,3,4,5,6,7,8,9,10};
    int choices, repeat, kill;
    repeat=5;
    while(repeat!=0)
    {
        cout<<"Who should I elimanate"<<endl;
        cin>>kill;
    }
}
Whoa! That's a lot of unnecessary (and some nonstandard and/or deprecated) #include s you've got there.

Now, to remove an element from an array, you have to first figure out where that element is in the array (which position), then you move all of the elements after that down a spot (by assigning those elements to the previous array position).
Note that this won't actually shrink the size of the array -- you can't really do that with plain arrays.

Or you could just switch over to std::vector (whose header you've unfortunately neglected to #include ) and use the erase member function after you've figured out which position the element is at.
Last edited on
Topic archived. No new replies allowed.