array duplicates

hi, i need to create a 1D array of numbers and print them as they are entered, however the number should only be printed if it is not a duplicate already in the array - the numbers must be between 1 and 100 inclusive.
i'm new to c++ and have little idea of how to do this, if anyone could help that'd be great. this is what i have already?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;

int main()
{
	const int SIZE=100;
	int array[SIZE];

	cout << "Enter a list of numbers: 
	for (int i=0; i<SIZE; i++)
		cin >> array[i];
	

} 
make a find function or use the one from <algorithm>
after cin >> array[ i ], check if it's between 1 && 100, then do a search in the array using the function you made, do whatever is appropriate for the return value of that
how would i implement the find function?
is it just find array [i] >1 && array [i] <100 ?
i have never used this function before
Have you encountered functions ?

Here is what the function should look like :
1
2
3
4
5
6
7
8
bool isInArray( int arr[], unsigned size, int value ) // i think it is more appropiate name than find
{
    for( unsigned i = 0; i < size; ++i ) {
        if( /* ____ */ )
            return true;
    }
    return false;
}


then in your for loop, it should look something like :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const int SIZE=100;
int array[SIZE];
int array_index = 0; // to specify where the next unique number will be stored

for( int i = 0; i < SIZE; i++ ) {
    cin >> array[ i ];

    if( /* input is between 1 && 100 */ ) {
        if( /*number is in array (use the function isInArray) */  ) {
            // do nothing
        } else {
            // store array[i] in array[ array_index ]
            // increment array_index
        }
    }
}


this can be simplified using not ! operator
Last edited on
still doesn't really make sense to me sorry but thanks anyway
what are value and unsigned size representing?
value is the number u want to search in the array

size is the size of the array ( u should use it in the for loop )
Topic archived. No new replies allowed.