Hi, I was working on my assignment and on compiling everything works perfect except at one place the compiler seems to skip the cin command.
Here is my code: the skipped command is highlited in red. This particular part is suppose to delete the every occurence of an integer entered by the user.
#include "stdafx.h"
#include<iostream>
#include<string>;
using namespace std;
typedef int* ArrayPtr;//creates a pointer for dynamic arrays.
void Erase(int [], int* ,int* );
int main()
{
char choice;
int itemCount= 0, SearchElement=0; //itemCount keeps track of the size, SearchElement is for the element needs to be deleted.
cout<<"You will be creating an array of integers. Please input the size of the array."<<endl;
cin>> itemCount;
ArrayPtr table; //declares table a pointer of defined type
table = new int[itemCount]; // creates a dynamic array called table
cout<<"Please select from the following menu."<<endl;
cout<<" E(Erase Array Content)\tC(Count Words)\tR(Reverse Words)\tQ(Quit)"<<endl;
cin>> choice;
cin.ignore();
switch(choice)
case 'E':
case 'e':
Erase(table, &itemCount, &SearchElement);
//for(int index=0; index < itemCount; index++)
//if (table[index] == SearchElement)
cout<<"The size of the array is: "<<itemCount<<endl;
return 0;
}
void Erase( int ar[], int *item, int *Search)// this function is suppose to delete every occurrence of the digit input by the user.the item is suppose to keep the count of the array size search is the item to be deleted.
{
cout<<"Please enter \t"<<*item<<" \t integers"<<endl;
for(int index=0; index < *item; index++)
cin>> ar[index];
cout<<"You can now select a number from the array whose all occurences can be deleted \n.";
cout<<"Please select number to be deleted from the array."<<endl;
cin>> *Search;// suppose to store the user input for the integer to be deleted.
for(int index=0; index<*item; index++)
if(ar[index]== *Search)
*item--;
return;
}