could someone help me with my code
Hello everyone, I'm new to this board and fairly new to programming and I'm trying to understand some concepts on arrays so I'm trying to make this little program. I have a future assignment coming up that has some of these concepts so I'm trying to understand them so I can apply it to my assignments.
I'm trying to delete a number from a list of numbers in an array
and the program is also suppose to delete duplicates but i have no idea how to do it in my for loop
the numbers of the list are these
0,1,4,4,5,2,1,7,7
so if the user puts in 0 first
the list becomes 1,4,4,5,2,1,7,7
if they put 4 instead
the list becomes
0,1,5,2,1,7,7
this is my code here
can somebody help me with what is going on i tried 4 but the output is wrong i got
0,1,4,5,5,2,1,7 instead of 0,1,5,2,1,7,7
Code:
#include <iostream>
#include <string>
using namespace std;
void Get_Number(int &Number_to_Delete){
cout << endl << "Enter number to delete."<<endl;
cin >> Number_to_Delete;
}
void Delete_Number(int Number_to_Delete, int array[],int &count){
cout<< "The number " <<Number_to_Delete<< " is going to be deleted." <<endl;
for(int i=0;i<count;i++){
if(Number_to_Delete==array[i]){
array[i]=array[i+1];
}
}
count--;
}
void Display_Numbers(int array[],int &count){
for(int i=0;i<count;i++){
cout <<array[i];
}
}
int main(){
int list[9]={0,1,4,4,5,2,1,7,7};
int Number_to_Delete;
int count = 9;
Display_Numbers(list,count);
Get_Number(Number_to_Delete);
cout << "You want to delete the number "<< Number_to_Delete << endl;
Delete_Number(Number_to_Delete,list,count);
Display_Numbers(list,count);
system("pause");
}
My output for this code
014452177
Enter number to delete.
4
You want to delete the number 4
The number 4 is going to be deleted.
01455217
Press any key to continue . . .