Skip to content

Loop asking user for input into an array

An answer to this question on Stack Overflow.

Question

You all have helped me so much in the past, I am coming back for more help!

I am working on another C++ assignment for school. I have to collect 20 numbers between 10 and 100 from the user and compare them all and print out the ones that are not duplicates.

The part I am stuck on is trying to get the user input to loop until I have all 20 numbers. What I have makes sense to me, but it apparently is not working. Sorry for the ridiculous comments, I have to comment everything for class.

Any light you can shed on my goof up would be amazing! Thank you so much!

int FindDuplicates[20]; // my little array
int UserInput; // the number from the user to compare
int count; // the number of numbers entered
for(count=0; count<FindDuplicates; count++;) // what I am trying to do is have count start at 0. as long as it is less than the max array, add 1 to the count
{
    cout << "Please enter a number between 10 and 100: "; // print out what I would like
    cin >> UserInput; // get the number from the user
}

Answer

There is a syntax error on the line below, check how for statements work. There's also a problem with the <FindDuplicates. Make sure you understand what that variable means.

for(count=0; count<FindDuplicates; count++;)