Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider this data sequence: \"3 11 5 5 5 2 4 6 6 7 3 -8\". Any value that is th

ID: 3650128 • Letter: C

Question

Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value is considered a CONSECUTIVE DUPLICATE. In this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6. Note that the last 3 is not a consecutive duplicate because it was preceded by a 7.

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.

Explanation / Answer

please rate - thanks

#include <iostream>
using namespace std;
int main()
{int n,consec=0,prev=-1;
bool neww=false;
cout<<"Enter number <0 to exit): ";
cin>>n;
while(n>0)
    {
    if(n!=prev)
         {neww=true;
         prev=n;
         }
    else
         if(neww==true)
            consec++;
         else
             neww=false;
    cout<<"Enter number (<0 to exit): ";
    cin>>n;
    }
cout<<"There were "<<consec<<" sets of consecutive numbers ";
system("pause");
return 0;
}