Need some help!

I want to write a code where will be given n integer numbers.The program will print the two numbers whose difference is the closest.It will show any two, if there are many numbers giving the same minimum difference.
I wrote a code but I don't get the desired result.Would you give me some help? :)

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
#include <iostream>
#include <fstream>
using namespace std;

void sortNumber(int list[],int num)
{
    for(int i=1; i < num-1; i++)
    {
        int min=i;
        for(int j=i+1; j<num; j++)
            if (list[j]<list[min])
                min=j;
        swap (list[min],list[i]);
    }
}

void getData (int list[], int num)
{
    int n;
    ifstream fin ("input.txt");
    cin >> n;
    for (int i=0;i<n;i++)
        cin >> list[i];
}

int main ()
{
    int diff,list,num,n,a,b;
    int mindiff=8888;
    for (int i=0;i<n;i++){
    cin >> list[i];
    sortNumbers(list,num);
    for (int =0;i<n;i++){
        diff=list[i+1]-diff[i+1];
        if (diff<mindif) mindiff=diff;
        a=list[i];
        b=list[i+1];
    }
    }
    cout << a << b;
    return 0;
}
Topic archived. No new replies allowed.