C++ Code Example: searchs an array for a number

This code example allows the user to search for a number in an array. With a for loop each array element is checked if it matches the number to be searched.

#include <iostream>
using namespace std;

int main () {
    int number, i, arrayLength;
    bool numberInArray = false;
    int numbers[] = {65, 35, 23, 75, 76, 33, 12, 9};

    cout << "What number are you looking for " << endl;
    cin >> number;

    arrayLength = end(numbers) - begin(numbers);
    
    // loop over array and search for number
    for(int i = 0; i < arrayLength; i++) {
        if(number == numbers[i]) {
            numberInArray = true;
            break;
        }
    }

    // if boolean varible numberInArray is true ouput "found", 
    // if not output "not found"
    cout << (numberInArray ? "found" : "not found") << endl;
}