⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 caishuyouxi.txt

📁 一个小型的猜数字游戏源代码 供大家娱乐学习使用
💻 TXT
字号:
#include<stdlib.h>
#include<stdio.h>
#include <time.h>
void main()
{   int a,b,f,g,h,i,j,s,p,m=3,n=3,Nlocation=0,Nnumber=0,again,
        question[4],answer[4];
    char choose;
    printf("Welcome to the number puzzle game!\n");
    do{ printf("*************************************************\n");
          printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
         printf("Please wait for seconds.\nProgramme is building random digit...\n");
       loop:
            srand((unsigned)time(NULL));
            a=rand()%8642+1234;
            h=a;                                                        printf("%d",h); 
        for(m=3;m>=0;m--)
           { question[m]=a%10;
               a=a/10;
            }
        for(s=0;s<=3;s++)
           for(p=0;p<=3;p++)
            { if((s!=p)&(question[s]==question[p])||(question[s]==0))
              goto loop;
            }
        do{ printf("OK!!\nPlease enter a four-digit:\n");
              scanf("%d",&b);
            for(n=3;n>=0;n--)
                 { answer[n]=b%10;
                   b=b/10;
                 }
              for(i=0;i<=3;i++)
               for(j=0;j<=3;j++)
                { if(question[i]==answer[j])
                      Nnumber++;
                   if((question[i]==answer[j])&(i==j))
                     Nlocation++; 
                 }
              printf("The number of correct figures:\n---%d---\n",Nnumber);
              printf("The correct figures:\n");
              for(f=0;f<=3;f++)
                for(g=0;g<=3;g++)
                 { if(question[f]==answer[g])
                   printf("---%d---\n",question[f]);
                 }
              printf("Location of the correct number of figures:\n");
              printf("---%d---\n",Nlocation);
              if(Nlocation!=4)
                { printf("Sorry,do you want gusse once more?[y/n]\nOr get the answer?[a]");
                  flushall();
                    scanf("%c",&choose);
                     { if((choose=='y')||(choose=='Y'))
                         { Nlocation=0;
                            Nnumber=0;
                            printf("_________________________________________________\n");
                            continue;
                         }      
             else if((choose=='a')||(choose=='A'))
      {      printf("The correct figures is:\n---%d---\n",h);
            printf("*************************************************\n");
             printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
             printf("Do you want restart the game?[y/n]\n");
             flushall();
             scanf("%c",&choose);
             if((choose=='Y')||(choose=='y'))
              { Nlocation=0;
                Nnumber=0;
                 printf("_________________________________________________\n");
                 goto loop;
               }
               else 
                 break;
      }
             else
                break;
           }
      }
                printf("Congratulations on a full-guess!\nDo you want restart the game?[y/n]\n");
                flushall();
                scanf("%c",&choose);
      }while(Nlocation!=4);
         if((choose=='Y')||(choose=='y'))
             { Nlocation=0;
                Nnumber=0;
                again=1;
             }
           else
               again=0;
      }while(again==1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -