#include #include // The first loop searches through the array and // counts the number of odd entries. // // The second loop searches through the array and // counts the number of odd entries that follow an // odd entry. // // The third loop searches through the array and // finds the longest sequence of odd entries. // // Find and fix any bugs. // Function declarations int main(); // Function definitions int main() { int data[30]{ 27, 0, 1, 13, 25, 18, 16, 4, 28, 30, 23, 12, 8, 11, 17, 10, 15, 2, 6, 3, 5, 29, 22, 9, 14, 24, 20, 7, 26, 19 }; std::size_t const capacity{ 30 }; int odd_count{ 0 }; for ( std::size_t k{ 0 }; k < capacity; ++k ) { if ( data[k]%2 != 0 ) { ++odd_count; } } std::cout << "There are " << odd_count << " odd entries." << std::endl; odd_count = 0; for ( std::size_t k{ 1 }; k < capacity; ++k ) { if ( (data[k - 1]%2 != 0) && (data[k]%2 != 0) ) { ++odd_count; } } std::cout << "There are " << odd_count << " odd entries following an odd entry." << std::endl; odd_count = 0; for ( std::size_t k{ 0 }; k < capacity; ++k ) { int tmp_count{ 0 }; // If we are at an odd entry, keep going // forward until we reach an entry that is // not odd, or until we reach the end of // the array, and count the odd entries. while ( (k < capacity) && (data[k]%2 != 0) ) { ++tmp_count; ++k; } if ( tmp_count > odd_count ) { odd_count = tmp_count; } } std::cout << "The longest sequence of odd entries is " << odd_count << " entries long." << std::endl; return 0; }