the result of my code is 0 and i don't know why, can someone help me? : Can somebody help me please. The question is to print out the smallest prime number but bigger than other not prime number. after hours of work, my code print out 0 no matter what i type in, can anyone tell me where i go wrong? sorry for bad english, i have try to translate my code into english for you. Hope it help (i post this yesterday but because of my lack of communication ability, no one seem to firgue out the problem, i have tried harder, hoping today will be different)
for example: 4 7 8 9 then the result is 9 because 9 is the smallest prime number and bigger then the biggest non-prime number ( which is 8) here is my code:



    #include <iostream>
    #include <cmath>
    #include <complex>
    using namespace std;

    void TypeIn(int a[] ,int &n)
        {
                cout<< "\nType in n: ";
                cin >> n;
                for(int i=0; i<n; i++)
                    {
                    cout << "a[" << i << "]= ";
                    cin >> a[i];
                    }
        }
    int CheckPrimeNum(int Number)
    {
        int Count=0;
        int Divisor =1;
        while (Number >= Divisor)
        {
            if(Number % Divisor == 0)
            {
                Count++;
            }
        Divisor++;
        }
        return Count;
    }
    int BiggestNotPrime(int a[], int n)
    {
        int BiggestNotPrime =0;
        for( int i=0; i<n; i++)
        {
            if( CheckPrimeNum(a[i]) !=2)
            {
            BiggestNotPrime = a[i];
            break;
            }
        }
        if(BiggestNotPrime ==0)
        {
            return 0;
        }
        else
        {
        for( int i=0; i<n; i++)
        {
            if(CheckPrimeNum(a[i])!=2 && a[i] > BiggestNotPrime)
            BiggestNotPrime =a[i];
        }
        return BiggestNotPrime;
        }
    }
    int main()
    {
        int n;
        int a[100];
        TypeIn(a,n);
        int SmallestPrimeLocation =0;
        for(int i=0; i<n; i++)
        {
            if(CheckPrimeNum(a[i])==2 && a[i]> BiggestNotPrime(a,n))
                SmallestPrimeLocation =i;
                break;
        }
        if(SmallestPrimeLocation ==0)
        {
            cout << 0;
        }
        else
        {
            for(int i=SmallestPrimeLocation; i<n; i++)
            {
                if(a[i]>BiggestNotPrime(a,n) && a[i] < a[SmallestPrimeLocation] && CheckPrimeNum(a[i])==2)
                {
                    SmallestPrimeLocation=i;
                }
            }
            cout << a[SmallestPrimeLocation];
        }
        return 0;
    }

