I'm trying to figure out how to remove integers from an array. The homework problem has this desired output of:
Enter input file name: t1.txt
Min Number: -3
Number Count
2 3
1 1
-3 1
But what I'm getting is this output:
Enter file input name: t1.txt
Min Number: 1
Number Count
2 3
10 1
2 3
1 1
2 3
Which isn't what I need as the duplicates are still showing. My issue is that the text file the teacher provides for this has 5 integers in it. Which is all fine and dandy, but that means the code to get this specific output needs to remove integers from whatever he is printing out. I'm just having a hard time figuring out exactly how to remove integers from an array like this.
I've tried to implement a std::find bit within a for loop so that it finds the duplicates and replaces those values within a array with 0, but that didn't work and it just kept chugging along ignoring that bit of code. I've also tried to sort the array, but my problem is that it won't output in the same way as the desired output which has the numbers in the same order as the .txt file that I'm reading from.
#include <iostream>
using namespace std;
int main()
{
//initializer section
int dupliCounter[30];
int txtArray[30];
//Section to find out how many numbers are duplicates
for (int x = 0; x < size; x++)
{
int temp = txtArray[x];
for (int y = 0; y < size; y++)
{
if (temp == txtArray[y])
{
dupliCounter[x] += 1;
}
}
}
//Final formatting section
cout << "Min Number: " << min << endl;
cout << endl;
cout << "Number Count" << endl;
for (int k = 0; k < size; k++)
{
if (dupliCounter[k] != 0)
{
cout << txtArray[k];
cout << " ";
cout << dupliCounter[k] << endl;
}
}
}
I have it at a point where the code can detect repeated numbers, and then modifies another value that is basically counting how many times it repeats, but I can't figure out a way to get it to delete multiple instances of the same number.
Thank you for the help everyone!