Answer:
int firstNumber,secondNumber = -1, duplicates = 0;
do {
cin >> firstNumber;
if ( secondNumber == -1) {
secondNumber = firstNumber;
}else {
if ( secondNumber == firstNumber )
duplicates++;
else
secondNumber = firstNumber;
}
} while(firstNumber > 0 );
cout << duplicates;
Explanation:
Write some code that uses a loop to read such a sequence of non-negative integers, terminated by a negative number. When the code exits the loop it should print the number of consecutive duplicates encountered. In the above case, that value would be 3. We test the following on a C++ platform.
int firstNumber,secondNumber = -1, duplicates = 0;
do {
cin >> firstNumber;
if ( secondNumber == -1) {
secondNumber = firstNumber;
}else {
if ( secondNumber == firstNumber )
duplicates++;
else
secondNumber = firstNumber;
}
} while(firstNumber > 0 );
cout << duplicates;