Write the following function that tests whether the array has four consecutive numbers with the same value.

Write a test program that prompts the user to enter a series of integers and displays true if the series contains four consecutive numbers with the same value. Otherwise, display false. Your program should first prompt the user to enter the input size, i.e., the number of values in the series.
```

Enter the number of values: 9
Enter the values: 2 5 5 5 3 4 4 4 4
true



Enter the number of values: 5
Enter the values: 2 5 5 5 4
false

```


```
#include
#include
using namespace std;

bool isConsecutiveFour(vector values)
{
for (int i = 0; i < values.size() - 3; i++)
{
bool isConsecutive = true;
for (int j = i; j < i + 3; j++)
{
if (values[j] != values[j + 1])
{
isConsecutive = false;
break; // No consecutive sequence starting at i
}
}

if (isConsecutive) return true;
}

return false;
}

int main()
{
cout << "Enter the number of values: ";
int size;
cin >> size;

vector values(size);

cout << "Enter the values: ";
for (int i = 0; i < values.size(); i++)
cin >> values[i];

cout << (isConsecutiveFour(values) ? "true" : "false") << endl;

return 0;
}


bool isConsecutiveFour(vector values)
{
int count = 0;
for (int i = 1; i < values.size(); i++)
{
if (values[i - 1] == values[i])
count++;
else
count = 0;

if (count == 4) return true;
}

return false;
}
```

Computer Science & Information Technology

You might also like to view...

Which logical unit of the computer is the receiving section?

a. input unit b. output unit c. memory unit d. central processing unit.

Computer Science & Information Technology

Which of the following text error messages can indicate that BIOS could not find a hard drive? (Choose all that apply).

A. Drive not recognized B. No boot device available C. Hard drive not found D. A disk read error occurred

Computer Science & Information Technology

Macros are stored in modules

Indicate whether the statement is true or false

Computer Science & Information Technology

A slicer includes a slicer header that specifies the category of the slicer items

Indicate whether the statement is true or false

Computer Science & Information Technology