C言游

除代码外均由李明女完成,本程序只是部分基本功能

名称猜数字

使用C

规则电脑随机生成一个1-30的数字,人和电脑猜一个数字,的数字较为接近生       成的数字.

要求人和电脑各有10000,玩家多少分,分数上限500,非正常分数,提示错误      并要求重新,直到入正确范围为.运行游和一局完了的候要示游.

内容有

    帮助明游戏规则.

    始游入游.

    查询记录查询程序始到在的输赢记录.记录最多50,便将上面的分数.             记录的内容有电脑生成的数,玩家和电脑猜的数,以及.

    退出游束程序.

一局完了,,都要出相的激励或鼓励的,,出的不少于4,随机.

例如

第一局,:太棒了,!

第二局,:太好了,你怎做到的!

的情况也.

当一方分数小于等于0,判定一方.

当在菜9999,启无模式,即无猜都是玩家.

1、产生随机数的方法:

本函数用来取得随机数。本函数会自的从 0 RAND_MAX-1中取一个随机数。得注意的是使随机数的乱度最大,次在取随机数之前最好使用 srand() 以配置新的随机数 

#include   <stdio.h>  

  #include   <stdlib.h>  

  #include   <time.h>  

   
  /*
要用到上面几个.h文件。*/  

   

  int   i;  

  time_t   t;  

   
  srand((unsigned)   time(&t));  

  i=rand() % 500; //0~500 

2fflush(stdin)

fflush(stdin)刷新冲区,把冲区里的西

函数名: fflush

功 能: 清除一个流

用 法: int fflush(FILE *stream);

#include <stdio.h>
int main()

{     int a;

    char c;

    do
    {
        scanf("%d",&a);

        fflush(stdin);

        scanf("%c",&c);

        fflush(stdin);

        printf("a=%d     c=%c"n",a,c);

    }while(c!='N');

}     

system("cls");

system("cls");的意思就是DOS下的清屏命令“cls”

源代码:

#include <stdio.h>

 #include   <time.h>  

void main()

{

 int i,j;

 int times =0;

 char ch;

 do

 {

 srand((int)time(0));

 for(i=0;i<10;i++)

 {

       j=1+(int)(10.0*rand()/(20+1.0));

       printf(" %d ",j);

 }

 i=100 + j%201;

 do

 {

       printf("输入一个100~300的数%d",i);

       scanf("%d",&j);

       if(i > j)

       {

             printf("过小"n");

       }

       else     if(i < j)

       {

                  printf("过大"n");

       }

       else

       {

                  printf("答对了"n");

                        break;

       }

       times++;

       if(times > 50)

       {

             printf("你太笨了,不要再猜了"n");

                  break;

       }

 

 }while(1);

       printf("你还继续猜吗?");

       fflush(stdin);

       scanf("%c",&ch);

 }while ((ch == 'Y' )||( ch== 'y'));

 

 //printf("%d",i);

}

posted on 2007-11-16 16:51  段静迪  阅读(590)  评论(0编辑  收藏  举报