在此代码基础上怎么添加一个循环,即用户在猜正确了,之后提醒用户:是否继续玩输入Y继续n退出。

#include
#include <time.h>
#include <stdlib.h>
using namespace std.

int main()
{
int data = 0;
srand(time(NULL));
data = rand()%100+1;

int input;
while (true)
{
    cin >> input;
    if (data == input)
    {
        cout << "恭喜你,猜对了" << endl;
        break;
    }
    else if (input < data)
    {
        cout << "猜小了" << endl;
    }
    else
    {
        cout << "猜大了" << endl;
    }
}

return 0;

}

在外面套一个循环不就行了?完全一样,都是while(true),后面如果输入是N就 break

你可以在最外层再加一个循环,如果输入如果猜对了就判断用户输入,如果输入y就break,如果n就runtun