Practice
Collect Five Negatives
2026/Feb/Mar·Variant 2·Q2·[6 marks]
EASYValidation
Read numbers one at a time until five negative numbers have been stored in array NegNumbers. If a number is not negative, output Please enter a negative number and read again. When five negatives are stored, output Check complete followed by the five numbers, one per line.
Input: Numbers until five negatives have been accepted.
Output: An error line for each rejected value, then Check complete and the five stored numbers.
Example:
Input: 5
-1
3
-2
-3
-4
-5
Output: Please enter a negative number
Please enter a negative number
Check complete
-1
-2
-3
-4
-5
Sample Test Cases
Test 1: Two positives rejected
Inputs: 5, -1, 3, -2, -3, -4, -5
Expected: Please enter a negative number
Please enter a negative number
Check complete
-1
-2
-3
-4
-5
Test 2: All five already negative
Inputs: -9, -8, -7, -6, -5
Expected: Check complete
-9
-8
-7
-6
-5