Hello all,
This is my first time posting in this forum. I searched and found a similar post from years ago, but was unable to find an answer. I'm hoping some of you may be able to help me.
I've been assigned a problem in which 20 integers must be read and only non-duplicate entries must be inserted into an array. The exact phrasing of the problem is as follows:
Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the array only if it isn’t a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Provide for the “worst case” in which all 20 numbers are different. Use the smallest possible array to solve this problem.
I'm experiencing difficulty in checking for previous entries as well as inputting them into the smallest array possible. You'll find comments in my code in the parts that I know are incorrect:
#include "stdafx.h"
#include <iostream>
using namespace std;
double desiredEntry;
void duplicateCheckAndInput( double noDupesArray[] )
{
for ( int counter = 1; counter <= 20; counter++ )
{
cout << "Please enter a value for array element #" << counter << endl;
cin >> desiredEntry;
// Will only check against current counter value, not all previous values
if( desiredEntry != noDupesArray[counter] )
noDupesArray[counter] = desiredEntry;
} // end for
} // end function
int main()
{
double noDupesArray[]; // Must have a size or value(s)
// Call method;
duplicateCheckAndInput(noDupesArray);
// Output the results: I'm using an upper limit of 20, but the actual array may not be that large
for(int outputCounter = 0; outputCounter < 20; outputCounter++)
cout << noDupesArray[outputCounter] << endl;
system("pause");
return 0;
}
I'm aware that my current code doesn't account for integers between 10 and 100, inclusive, but I'd rather get the basic validation and entry solved and then implement that part.
Any help is greatly appreciated. Thank you.