I am having a problem writting a function to remove all occurences of a specific (user defined) integer from an array.
Here is what I have so far.
#include<iostream>
using namespace std;
void menuDisplay(int& menuSelect);
void remove(int intArray[], int& sizeOfArray, int removeItem);
void removeAt(int intArray[], int& sizeOfArray, int index);
void removeAll(int intArray[], int& sizeOfArray, int removeAll);
void printArray(int intArray[], int sizeOfArray);
void insertAt(int intArray[], int& sizeOfArray, int insertItem, int index);
int main(){
int sizeOfArray = 10;
int index;
int intArray[10];
int menuSelect = 0;
cout << "Please enter numbers for array" << endl;
for (int f = 0; f < sizeOfArray; f++)
cin >> intArray[f];
cout << endl;
cout << "The array you entered is: " << endl;
cout << "**********************" << endl;
for (int f = 0; f < sizeOfArray; f++)
cout << intArray[f] << " ";
cout << endl;
cout << "**********************" << endl;
while (menuSelect != 6)
{
menuDisplay(menuSelect);
switch (menuSelect){
case 1:
int removeItem;
cout << "Enter item which you want to remove."<<endl;
cin >> removeItem;
remove(intArray, sizeOfArray, removeItem);
break;
case 2:
cout << "Please enter index" << endl;
cin >> index;
removeAt(intArray, sizeOfArray, index);
break;
case 3:
int removeAll;
cout << "Please enter number to remove multiple occurences." << endl;
cin >> removeAll;
removeAll(intArray, sizeOfArray, removeAll);
break;
case 4:
int insertItem;
cout << "Please enter insertItem and index." << endl;
cin >> insertItem >> index;
insertAt(intArray, sizeOfArray,insertItem,index);
break;
case 5:
printArray(intArray, sizeOfArray);
break;
default:
cout << "invalid selection" << endl;
}
}
return 0;
}
void menuDisplay(int& menuSelect)
{
cout << endl;
cout << "[[Menu]]" << endl;
cout << "1. removeItem" << endl;
cout << "2. removeAt" << endl;
cout << "3. removeAll" << endl;
cout << "4. insertAt" << endl;
cout << "5. print array" << endl;
cout << "Please make enter a number to continue." << endl;
cout << endl;
cin >> menuSelect;
}
void remove(int intArray[], int& sizeOfArray, int removeItem)
{
int num = 999;
int i;
for (int i = 0; i < sizeOfArray; i++)
if (intArray[i] == removeItem)
num=i;
if (num!=999)
{
for (int k = num; k < sizeOfArray; k++)
intArray[k] = intArray[k+1];
sizeOfArray--;
}
if(num==999)
cout << "Error" << endl;
}
void removeAt(int intArray[], int& sizeOfArray, int index)
{
if (index >= 0 && index < sizeOfArray)
{
for (int k = index; k < sizeOfArray; k++)
intArray[k] = intArray[k+1];
sizeOfArray--;
}
else
cout << "Error: the index you entered is out of range." << endl;
}
void removeAll(int intArray[], int &sizeOfArray, int removeAll)
{
int counter;
int num = 999;
int i, k;
for (int i = 0; i < sizeOfArray; i++)
if (intArray[i] == removeAll)
num = i;
if (num!=999)
{
for (int k = num; k < sizeOfArray; k++)
intArray[k] = intArray[k+1];
sizeOfArray--;
}
if(num==999)
cout << "Error" << endl;
}
void insertAt(int intArray[], int& sizeOfArray, int insertItem, int index)
{
if (index >= 0 && index < sizeOfArray)
{
for (int i = sizeOfArray; i > index; i--)
{
intArray[i] = intArray[i-1];
}
sizeOfArray++;
intArray[index]= insertItem;
}
}
void printArray(int intArray[], int sizeOfArray)
{
cout << "**********************" << endl;
for (int f = 0; f < sizeOfArray; f++)
cout << intArray[f] << " ";
cout << endl;
cout << "**********************" << endl;
}
Line (51) : error C2064: term does not evaluate to a function taking 3 arguments