gpt4 book ai didi

我的代码的 C++ 问题

转载 作者:行者123 更新时间:2023-11-28 04:49:00 24 4
gpt4 key购买 nike

<分区>

当我运行它并选择我的号码作为播放器后,计算机返回给我两个输出(而不是一个...)。我不知道为什么,你能帮我解释一下为什么会这样吗?

#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>

using namespace std;

int random(int a, int b)
{
int num = a + rand() % (b + 1 - a);
return num;
}

int main()
{
srand(time(NULL));

int myNum;
cout << "Choose your number, human: ";
cin >> myNum;

int min = 1;
int max = 100;
int comp;

string player;

while(1) {
comp = random(min, max);
cout << "Computer: " << comp << endl; // why does this get called twice??
getline(cin, player);

if (player == "too high") {
max = comp - 1;
cout << "min: " << min << " max: " << max << endl;
} else if (player == "too low") {
min = comp + 1;
cout << "min: " << min << " max: " << max << endl;
} else if (player == "correct") {
cout << "Computer found the number..." << endl;
break;
}
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com