Problem with arrays

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

 bool SearchBinary(int a, int t)
{
    int size = sizeof(a)/sizeof(int);
    cout << size;

    int low = 0;
    int high = size - 1;
    while (low <= high)
    {
        int i = (low + high)/2;
        if (t == a[i])
        {
            return true;
        }
        else if(t < a[i])
        {
            high = i- 1;
        }
        else
        {
            low = i + 1;
        }
        return false;
    }
}

int main()
{
    int array[256];
    for(int i=0;i<256;i++) {
        cout <<"Input for position number " << i+1
             <<"\n";
        cin >>array[i];
        cout <<"Add another integer?(Y/N) ";
        char repeatans;
        cin >>repeatans;
            if (repeatans == 'N'){
                break;
            }
    }
    cout << "Number to search for: "; << endl;
    int target;
    cin >> target;
    bool search_result = BinarySearch(&array[256], target);
    if (search_result == 'True')
    {
        cout <<"Integer was found";
    }
    else
    {
        cout <<"Integer was not found";
    }
}

}


I keep getting "error : invalid types ' int[int] ' for array subscripts on lines 18 and 22
a is an int and not an array.
Last edited on
Topic archived. No new replies allowed.