| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4011 人关注过本帖
标题:猜数字游戏
只看楼主 加入收藏
myhnuhai
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:3
帖 子:425
专家分:1725
注 册:2010-3-17
收藏
得分:0 
回复 4楼 谷雨寒
嗯,是随机数是1-100的随机数!

不要让肮脏的记忆,迷失了原本纯洁的心灵!
2010-06-14 21:56
wibx化吉
Rank: 2
等 级:论坛游民
帖 子:10
专家分:10
注 册:2010-6-3
收藏
得分:0 
回复 楼主 谷雨寒
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
main()
{
 int a[4],b[4],i,j;
 int num,time=0;
 int m=0,n=0,o=0;
 int ch=1,chch;
 char change[100];
 clrscr();      /*clean screen*/
 a[0]=rand()%10;    /*get a four number*/
 a[1]=rand()%10;
 a[2]=rand()%10;
 a[3]=rand()%10;
 while(1)  /*the number of every position not be same*/
 {
 if((a[0]==0||a[0]==a[1]||a[0]==a[2]||a[0]==a[3]||a[1]==a[2]||a[1]==a[3]||a[2]==a[3])==0)
  {
  printf("Notice:The first number is %d:",a[0]);
  break;
  }
 else
  {
  a[0]=rand()%10;
  a[1]=rand()%10;
  a[2]=rand()%10;
  a[3]=rand()%10;
  }
 }
 while(ch==1) /*circulate for guess or not*/
 {
  n=0;
  m=0;
  o=0;
  printf("Please input the num:");
  scanf("%d",&num);
  time++;
  while(1) /*input the right number of four*/
  {
   if(num<1000||num>9999)
   {
   printf("Number input wrong,input again:");
   scanf("%d",&num);
   }
   else
   break;
  }
  b[0]=num/1000;  /* deposit num to array b*/
  b[1]=(num-b[0]*1000)/100;
  b[2]=(num-b[0]*1000-b[1]*100)/10;
  b[3]=num-b[0]*1000-b[1]*100-b[2]*10;
  for(i=0;i<4;i++)
   if(a[i]==b[i])
    m++;
  for(i=0;i<4;i++)
   for(j=0;j<4;j++)
    if(a[i]==b[j])
     o++;
  if(m==4)
   {
   printf(" Aright Grameover!\n");
   printf("You have guess %d times\n",time);
   exit(0);
   }
  else if(time==8)
   {
    n=o-m;
    printf("Sorry,guess wrong:%dA%dB\n",m,n);
    printf("You have guess 8 times,do you want again(1-Yes,0-No):");
    scanf("%s",&change[100]);
   }
  else if(time==15)
   {
    printf("You have guess 15 times.Game Over!\n");
    exit(0);
   }
  else
   {
   n=o-m;
   printf("Sorry,guess wrong: %dA%dB\n",m,n);
   printf(" Guess %d times,again(1-Yes,0-No)?",time);
   }
  do
   {
    scanf("%s",&change[100]);
    switch(change[100])
    {
     case '0': exit(0);break;
     case '1': ch=1;break;
     default:{chch=1;ch=0;printf("Input Wrong input again(1-Yes,0-No):");}
    }
   }while(chch==1&&ch!=1);
 }
}
2010-06-16 23:55
快速回复:猜数字游戏
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014175 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved