c++问题:猜数字saehrt

一个猜数字游戏
我想加一个提示范围的功能

c++

using namespace std;
int i1 = 0;
int i2 = 0;
int* key;
int zuo[5] = {};
int you[5] = {};
void 左(int q);
void 右(int q);

int compare( int q[],int w) {

for (int i = 0; i < 5; i++) {
    if (q[i] > q[i + 1]) {
        int w = q[i];
        q[i] = q[i + 1];
        q[i + 1] = w;
    }
}

if (w == 1) {
    
    
    key = new int(q[4]);
    return key;
}
else if(w==2) {
    if (q[0] == 0) { return 100; }
    /*key = new int(q[0]);*/
    cout << q[4] << endl;
    return /**key*/q[0];
}

}
void 左(int q) {
zuo[i1] = q;
i1++;
compare(zuo,1);
}
void 右(int q) {
you[i2] = q;
i2++;
compare(you,2);
}
void 范围() {
cout << "范围为:" << compare(zuo, 1 )<< "--" << compare(you, 2) << endl;
}

int main()
{
//传数组不需要[]
srand((unsigned )time(NULL));
int x = rand() % 100 + 1;
int a, c = 0;
do {// do while 的好处 可以处理第一次cin 与while条件的问题
cout << "\n输入你的心仪数字吧\n";
cin >> a;
cout << "所选数字为:" << a << endl;
if (a > x) {
cout << "大了" << endl;
c++;
右(a);
范围();
}
else if (a < x) {
cout << "小了" << endl;
c++;
左(a);
范围();
}

        else  if (a = x) {
            cout << "猜中了!" << endl;
            break;
        }
        
        cout << "余剩次数:" << 6 - c << endl;


        if (c == 0 && a != x) {
            cout << "GG\n";

        }

    } while (0 < a && a < 101 && c < 6);
delete key;
return 0;

}

这个代码跑出来后 我输入57 它会提示55--100 好奇怪,当我cout出数组时 数组除了0之外居然还有些别的奇怪的数字
我想把输入的数字传入数组然后排大小输出 但是函数没法改变数组实参 因为数组没法用指针 我不知道怎么办了。

1.求 教教我怎么用传数组
2.这个情景用这么方法来比较大小更容易
3.更简易的做法