C++猜数字,不想玩的时候可以随时停止

猜十次,十次还没猜出来就问是否要再玩一次,但不想玩的时候可以随时停止。
我的代码输入z后会一直循环,请问应该怎么改?


#include <iostream>
using namespace std;```
int main()
{
    int a = 0;
    int b = 1;
    char ch = 'z';
    while (b == 1&&a!=ch)
    {
        srand((unsigned int)time(NULL));
        int num = rand() % 200 + 1;
        int count = 1;

        while (count <= 10)
        {
            cin >> a;
            if (a > num)
            {
                cout << "过大" << endl;
                count++;
            }
            else if (a < num)
            {
                cout << "过小" << endl;
                    count++;            
            }
            else if (a = num)
            {
                cout << "猜中啦!" << endl;
                break;
            }
        }cout << "输入1,继续猜下一个数;输入0,结束游戏:" << endl;
        cin >> b;
    }
    if (a = ch)
        cout << "游戏结束" << endl;
}


img


你的条件判断都在 while循环外面了,那你一轮游戏结束后输入0可以结束,输入1之后因为最后一次a不是'z',所以又进了while(count <= 10)的循环,你再输'z'只会被判断为猜数。。