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.
```
```
#include
#include
using namespace std;
bool isConsecutiveFour(vector
{
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
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
{
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;
}
```
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.
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
Macros are stored in modules
Indicate whether the statement is true or false
A slicer includes a slicer header that specifies the category of the slicer items
Indicate whether the statement is true or false