Matlab编写的猜数游戏 请问代码哪里出错了

n=round(rand(1,1)*100);
x=input('输入您猜的数x=');
s1=0;s2=0;
while (s1+s2)<=7
if x>n
s1=s1+1;
end
disp('High')
x=input('再次输入您猜的数');
if x<n

s2=s2+1;

end
disp('Low')
x=input('再次输入您猜的数');

if x==n
disp('You win');
end
disp(n)
end

你好,每个if都要把相关的语句放进去不要留在外面。然后猜中了要跳出循环
(有帮助望采纳哟)

n=round(rand(1,1)*100);
x=input('输入您猜的数x=');
s1=0;s2=0;
while (s1+s2)<=7
    if x>n
        s1=s1+1;
        disp('High')
        x=input('再次输入您猜的数');
    end
    
    if x<n
        s2=s2+1;
        disp('Low')
        x=input('再次输入您猜的数');
    end
    
    if x==n
        disp('You win');
        disp(n)
        break; % 最后要终止循环
    end
    
end