Entering a certain amount of values in array

I am trying to enter at least 5 and not more than 10 values in an array. When the user enters -1, the program ends. -1 should not be included in array. The array can only hold 10 values. if the user enters only 5 values the rest should be set to 0. I am having trouble with the number of values the user enters.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

  
  int num;
  int numOfInt = 0;   //number of values entered by user
  int array[10];
  
  cout << "enter values: ";
	do
	{
		cin >> num;

		array[numOfInt] = num;

		numOfInt++;

		if (num < 0)
		{
			numOfInt--;
		}
	} while (numOfInt >= 5 && numOfInt < 10 && num > 0);

Last edited on
Topic archived. No new replies allowed.