While loop and arrays

I'm trying to keep running the program to input numbers into an array unless the user inputs a 10. For some reason, when I input a 10 into the program, the loop doesn't break and it goes on continuously. Can somebody explain to me why my loop isn't working the way I want it to. My code is below.


1
2
3
4
5
   while (number[count] != 10)
   {
      cin >> number[count];
      count = count + 1;
   }
What type is number[count]?
it is an int
how are you putting the numbers into the program?
If I have understood your problem correctly, a for loop would do the job better.

1
2
3
4
5
6
for(unsigned int i = 0; i <10; i++) // keeps running until i is 10 or greater. updates i every time it loops.
{
      int k = 0;
      std::cin >>k;
      number[i] = k;
}
Topic archived. No new replies allowed.