The function should remove all the occurrences of an integer (say, removeItem) from an array. If the value does not exist or the array is empty, ,output an appropriate message.
My program is able to print the array without all the occurences of removeItem , but I don't know how to output appropriate message if the value doesn't exist or the array is empty. Any help will be greatly appreciated .
#include<iostream>
using namespace std;
const int ARRAY_SIZE = 10;
void removeAll(int list[], int ARRAY_SIZE, int removeItem);
int main()
{
int list[ARRAY_SIZE];
int index, removeItem;
cout << "Enter " << ARRAY_SIZE << " integers:" << endl;
for(index= 0; index < ARRAY_SIZE; index++)
cin >> list[index];
cin.ignore(100, '\n');
cout << "Enter the number to be removed: " << endl;
cin >> removeItem;
cout << "After removing " << removeItem
<< " the list is: " << endl;
removeAll(list, ARRAY_SIZE, removeItem);
cout << endl;
system("PAUSE");
return 0;
}
void removeAll(int list[], int ARRAY_SIZE, int removeItem)
{
int loc;
for(loc = 0; loc < ARRAY_SIZE; loc++)
if(list[loc] != removeItem)
cout << list[loc] << " ";
}