How to stop the input process when I input five negative integer?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int a[20],x;
	
	for(x=0; x<20; x++)
	 {
	 	cout<<"Enter integer: ";
	 	cin>>a[x];
	 	 
	 	while(a[x]<0)
		 {
		 	   while(x<5)x++;
		 	   { 
		 	    cout<<"Enter integer neg: ";
		 	    cin>>a[x];
		       }
		 }  
	 }


This should be the output

Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: -1
Input: -1
Input: -1
Input: 1
Input: -1
Input: 1
Input: -1

Stop!
Last edited on
How to stop the input process when I input a negative integer five times?


If you want to keep track of the number of negative integers you've entered, perhaps you should count them.
do you have a simple code for that?
No, but you have. You did count students with highest score, didn't you? Now count numbers with negative value. Think and adapt.
No this is not about students. This is about inputting positive and negative inputs and the program will only stop when I will input five negative integers.
No this is not about students.

Sure. But the suggestion was that you'd already written code to count "things" previously. It was the counting process which was referred to, not the "student-ness" of the things being counted.
Topic archived. No new replies allowed.