用C++编一个猜数字的游戏。最好用Visual C++6.0,并给出运行结果

计算机随机给出一个数,猜中就胜没猜中提示大了还是小了,直到猜中给出所用时间和猜了几次。程序后面标注算法说明,最好能详细一点。

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

int main(int argc, char * argv[])
{
    srand((unsigned)time(NULL));
    int a = rand()%100;
    a+=1;
    int b,c;
    c = 0;
    while (c < 10)
    {
printf("Please enter a number: ");
if (scanf("%d", &b) == 0)
{
   fprintf(stderr, "Invalid entry.\n");
   return EXIT_FAILURE;
}
else
{
   if (b == a)
   {
printf("You are correct, the number is %d!\n", a);
printf("You used %d times to get the answer.\n", c);
break;
   }
   else if (b > a)
printf("The number is bigger than it suppose to.\n");
   else
printf("The number is smaller than it suppose to.\n");
   c++;
}
if (c == 10)
{
   printf("You used 10 times, please try again!\n");
   break;
}
    }

    return EXIT_SUCCESS;
}
温馨提示:答案为网友推荐,仅供参考
相似回答