Q:

Why is my program for, minimum difference between ANY TWO elements in an array, giving opposite result?

This might sound like a repeat question but it is not in my perspective because i havent found the answer to my question inspite of being through several references as listed below.
Following is my program and my own attempt to try and find the "Minimum difference between two elements within the array, any two pairs", then let be there more than one pair of numbers which gives the same minimum difference numerically. I tried to change loops to count them differently and also tried to change the if condition clause for different results but finally ended up with the following code:
#include <iostream>                     //input output stream   
#include <cstdlib>
#include "math.h"                       //to be able to use math functions if any

using namespace std;

int main()

{

    int x=0,y=0,number1 = 0,number2 = 0,size1=0,mindiff = 0;
    int index = 0, count = 0, diff = 0;
    cout<<"enter the size of array you want \n\n";
    cin>>size1;
    int arr1[size1];
    cout<<"\n\n please enter elements of array \n\n";

    for (int i =0;i<size1;i++)
    {
        cin>>arr1[i];
    }
    for ( x=0;x<size1;x++ )
    {
        diff = 0;
        for ( y=0;y<size1;y++ )
        {
            diff = abs(arr1[x] - arr1[y]);
            if (diff<mindiff)
            {
                mindiff = diff;
                //index = x+1;
                number1 = arr1[x];
                number2 = arr1[y];
            }
        }

        }   

cout<<"\nthe elements amongst which the minimum difference was given are "<<number1<<" & "<<number2<<endl;
cout<<"the difference between them is "<<abs(mindiff)<<endl;

system("pause");
return 0;
}

//end of program

I went through the following references and a lot more to really need to list down here. However a few of the references in my search and study are as follows:-
Minimum difference in an array 
Finding out the minimum difference between elements in an arrays
Find the minimum difference between two arrays
Find the minimum difference between two arrays
Dividing an array into two subsets of equal sizes having minimum difference in sum of values
http://www.geeksforgeeks.org/find-the-minimum-distance-between-two-numbers/
http://programmingpraxis.com/2013/10/15/find-the-minimum-difference/#comment-9146
https://www.daniweb.com/programming/software-development/threads/391082/distance-between-two-closest-elements-in-an-array
All the above references and lots more but could not find any that aligns to my point of view hence i know that i am doing something really silly wrong out here because i get a maximum difference and not minimum difference.
Where am I going wrong in the above logic? 
I anyways have to keep on assigning the new minimum every time a lower difference is found as written in the if condition statement right???
following is the output
enter the size of array you want
6
please enter elements of array
1
2
34345
7
8
9
the elements amongst which the minimum difference was given are 1 & 34345
the difference between them is 34344
Press any key to continue . . .

A:

Taking the advice from Beta and also looking at the only answer that i found aligning with my code perspective, i came up with the following smal but critical edit of my own code above. Not much change but a very important and essential change.
PFB the code which indicates that fact that i had a logical error in not loading the difference value temporarily in a variable before exiting the innermost loop for the next iteration for comparing the absolute difference value.
#include <iostream>                             //input output stream   
#include <cstdlib>
//#include <vector>         not used            //to enable usage and implementation of vectors
#include "math.h"                               //to be able to do complex math functions if any
//#include <algorithm>      not used            //to be able to use max_element() and distance() functions on iterator.

using namespace std;

int main()

{

/*
first different variables for loop counters and 
size of array is taken in advanced instead of calculating during the program to reduce program time

*/

    int x=0,y=0,number1 = 0,number2 = 0,size1=0,mindiff = 0;
    int index = 0, count = 0, diff = 0;
    cout<<"enter the size of array you want \n\n";
    cin>>size1;
    int arr1[size1];
    cout<<"\n\n please enter elements of array \n\n";

    for (int i =0;i<size1;i++)
    {
        cin>>arr1[i];
    }
    for ( x=0;x<size1;x++ )
    {

        for ( y=0;y<size1;y++ )
        {
        if (x!=y)
/*
now load the difference in a variable named diff
and use a comparisional conditional statement to select
value of minimum difference
*/
            {
            diff = abs(arr1[x] - arr1[y]);
                if(count == 0)
                {
                    mindiff = diff;
                }
            else
                {
                    if (diff<mindiff)
                    {
                    cout<<diff<<" minimum difference "<<"\n";
                    mindiff = diff;
                    //index = x+1;
                    number1 = arr1[x];
                    number2 = arr1[y];
                    }
                }
            count++;
            }
        }

    }

cout<<"\nthe elements amongst which the minimum difference was given are "<<number1<<" & "<<number2<<endl;
cout<<"the difference between them is "<<abs(mindiff)<<endl;
cout<<endl<<endl;

system("pause");

return 0;
}

This lets me perceive that perspective of coding does work for this case. Sure it might be slow and inefficient but its a result.
gratitude to all for their time.

