Q:

C++ code malfunctioning

I wrote a basic linear search C++ code. Whenever I run this, the result I get is always the opposite of the expected result.
For instance, I want to search 4. In an array where it is present, it will say the number is not found, but upon searching an absent element, it will say the element is found at position 0.
Even after an hour or so of constantly looking at the code I have not found any solution.
#include <iostream>
using namespace std;

//scanning program
int linearsearch (int A[] , int z, int n, int srchElement) {
    for (int z = 0; z < n; z++) {
        if (A[z] == srchElement) {
            return z;
        }
    }
    return -1;
}

//main program
int main () {
    int i, n, A[1000], z;
    //asking for size of array
    cout << "give size of the array needed to be scanned: ";
    cin >> n;
    cout << endl;
    if (n > 999) {
        cout << "invalid value";
        return -1;
    }
    //making sure of the size of the array
    cout << "enter " << n << " integers: ";
    //asking for the array
    for (i = 0; i < n; i++) {
        cin >> A[i];
    }
    int srchElement, index;
    do {
        cout << endl << "enter element to search (-1 to exit ): ";
        //srchElement is defined here
        cin >> srchElement;
        if (srchElement == -1) break;
        index = linearsearch(A, n, srchElement, z);
        //calling thscanning function
        if (index == -1) {
            cout << srchElement << " not present" << endl;
        }
        //outputting the results of the scan
        else {
            cout << srchElement << " present " << index << endl;
        }
    } while (true);
    return 0;
}

A:

This is your search function correctly formatted:
int linearsearch (int A[] , int z, int n, int srchElement) 
{
    for (int z = 0; z < n; z++)
    {
        if(A[z] == srchElement)
            {return z;}
    } 
    return -1;
}

and here is how you call it:
index=linearsearch(A, n, srchElement, z);

You pass a value z in with the call. It is unitialised and does nothing, in main() or in the function.
You pass the arguments into the function in the wrong order. You are:

passing n (from main()) into the unused z value
searching for the uninitialised z (from main())
passing in the element you are looking for as n (array size). (This will quite likely result in out of bounds error, e.g. if searching for -1)

Try this:
int linearsearch (int A[], int n, int srchElement) 
{
    for (int z = 0; z < n; z++)
    {
        if(A[z] == srchElement)
            {return z;}
    } 
    return -1;
}

and here is how you call it:
index=linearsearch(A, n, srchElement);

