小编Mr *_*ade的帖子

rand()随机数生成C++

我正在尝试使用该rand()函数生成伪随机整数.它的工作原理,但我的问题是它始终为int选择相同的名称.(在这种情况下,它是41.我想如果你把rand()主要的while循环放在85或者什么东西.)

有没有办法来解决这个问题?这是我的代码:

    #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>

    int guess;
    int danse = rand() % 101;

    using namespace std;

    void more(){
    cout << "The number that you need to guess is higher!";

    return;
    }

    void lower(){
    cout << "The number that you need to guess is lower!";

    return;
    }

    int main(){
    while(1){
    cout << "\nGuess a number 0-100: ";
    cin >> guess;

    if (guess > danse){
        lower();
}
    if (guess < danse){
        more();
}

    if (guess …
Run Code Online (Sandbox Code Playgroud)

c++ random

-4
推荐指数
1
解决办法
1311
查看次数

标签 统计

c++ ×1

random ×1