hi i am brand new to c++ so please bear with me
i am trying to make a program that reads in an array of numbers between 1 and 100, as they are read in it will print them unless they are a duplicate number of one already in the array... this is the code i have so far and nothing is working
if someone could show me the code that would do this i would be so grateful, thanks so much!
Your if statement will alway be false, since you're checking if a number IS NOT equal to itself, which is never true.
What you can do is fill the array, then print the first number. Then, for each element after that, check to see if it has already been printed. If it has been printed, skip it and move to the next one.
constint SIZE = 100;
int main( )
cout << "Enter numbers:" << endl;
for (int i = 0; i < SIZE; i ++)
cin >> array[i];
//This first loop will simply fill the array
cout << array << " "; // this will print the first element
for (int i = 1; i < SIZE; i++)
for (int j = 0; j < i; j++)
if (array[i] == array[j])
repeated = true;
if (repeated == false)
cout << array[i] << " ";
I hate to give out code, but this problem could be tricky. Use a boolean to test for repetition (you can either break out or not). And only print the array element if the boolean is false.