用C++写的猜数字游戏

Posted 辉仔仔百毒不侵

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用C++写的猜数字游戏相关的知识,希望对你有一定的参考价值。

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()

    srand(time(NULL));
    int N=rand()%1000+1;
    int result=rand()%N;
    int guess=0;
    int count=0;
    int len=0;
    printf("I've picked the number,and it's somewhere between 1 and %d\\n",N);
    do
        printf("please input you guuessing:");
        scanf("%d",&guess);
        count++;
        if(guess>result)
           len=(result+1)+rand()%(guess-result+1);//产生在m,n之间的随机数:int a=m+rand()%(m-n+1);
            printf("May be it's a smaller number than at least %d,",len);
        else if(guess<result)
        
            len=guess+rand()%(result-guess);
            printf("May be it's a bigger number than at least %d,",len);
        
    while(guess!=result);
    if(count==1) printf("The number of 1\\nDid you trade life for luck after just one guess");
       else if(count<15) printf("The number of %d\\nI admit you may be a genius at this",count);
       else printf("The number of %d\\nMaybe even fewer guesses,right");
    return 0;
    

以上是关于用C++写的猜数字游戏的主要内容,如果未能解决你的问题,请参考以下文章

用C语言实现一个简单的猜数字游戏

python写简单的猜数字游戏

Python实现简单的猜数字游戏

JS中的猜数字游戏

python小练习简单的猜数字游戏

游戏:猜数字2.0(C++)[二分]