鱼C论坛

 找回密码
 立即注册
查看: 3955|回复: 8

求高手帮忙看看

[复制链接]
发表于 2013-9-11 21:17:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <dos.h>

void guess(int n)
{
   int acount, bcount, i, j, k = 0, flag, a[10], b[10];
   do
   {
      flag = 0;
          srand((unsigned)time(NULL));
          for(i = 0; i < n; i++)
                  a[i] = rand()%10;
          for(i = 0; i < n - 1; i++)
          {
             for(j = i + 1; j < n; j++)
                         if(a[i] == a[j])
                         {
                            flag = 1;
                                break;
                         }
          }
   }while(flag == 1);
   do
   {
      k++;
          acount = 0;
          bcount = 0;
          printf("guess:");
          for(i = 0; i < n; i++)
                  scanf("%d", &b[i]);
          for(i = 0; i < n; i++)
                  for(j = 0; j < n; j++)
                  {
                     if(a[i] == b[i])
                         {
                            acount++;
                                break;
                         }
                         if(a[i] == b[j] && i != j)
                         {
                            bcount++;
                                break;
                         }
                  }
                  printf("clue on: %d A %d B\n\n", acount, bcount);
                  if(acount == n)
                  {
                     if(k == 1)
                                 printf("you are the topmost rung of Fortune's ladder!! \n\n");
                         else if(k <= 5)
                                 printf("you are genius!! \n\n");
                         else if(k <= 10)
                                 printf("you are cleaver!! \n\n");
                         else
                                 printf("you need try hard!! \n\n");
                         break;
                  }
   }while(1);
}

void main()
{
   int i, n;
   while(1)
   {
      clrscr();
          gotoxy(15, 6);
          printf("1. start game?(y / n)");
          gotoxy(15, 8);
          printf("2. Rule");
          gotoxy(15, 10);
          printf("3. exit\n");
          gotoxy(25, 15);
          printf("please choose:");
          scanf("%d", &i);
          switch(i)
          {
             case 1:
                         clrscr();
                         printf("please input n:\n");
                         scanf("%d", &n);
                         guess(n);
                         sleep(5);
                         break;
                 case 2:
                         clrscr();
                         printf("\t\tThe Rules Of The Games\n");
                         printf("step1: input the number of digits\n");
                         printf("step2: input the number, separated by a space between two numbers\n");
                         printf("step3: A represent location and data are correct\n");
                         printf("\tB represent location is correct but data is wrong!\n");
                         sleep(10);
                         break;
                 case 3:
                         exit(0);
                 default:
                         break;
          
          }
   }
}

--------------------Configuration: 猜数字 - Win32 Debug--------------------
Compiling...
猜数字.c
D:\C语言\MSDev98\MyProjects\猜数字\猜数字.c(69) : warning C4013: 'clrscr' undefined; assuming extern returning int
D:\C语言\MSDev98\MyProjects\猜数字\猜数字.c(70) : warning C4013: 'gotoxy' undefined; assuming extern returning int
D:\C语言\MSDev98\MyProjects\猜数字\猜数字.c(86) : warning C4013: 'sleep' undefined; assuming extern returning int

猜数字.obj - 0 error(s), 0 warning(s)
这是什么问题啊


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-9-11 22:10:13 | 显示全部楼层
本帖最后由 福禄娃娃 于 2013-9-11 22:21 编辑

缺少头文件 #include <Windows.h>

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-9-12 11:55:49 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-9-12 12:21:29 | 显示全部楼层
  1. gotoxy(15, 10);
复制代码
楼主这函数哪来的???
  1. clrscr()
复制代码
函数的头文件是
  1. #include <conio.h>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-9-12 15:43:05 | 显示全部楼层
很神奇啊,这是什么意思?if(a == a[j])  // guess函数的do....while()
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-9-12 16:29:46 | 显示全部楼层
哎哟,没注释,根本不想看!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-9-13 14:06:13 | 显示全部楼层
你输要这个效果吗?

                               
登录/注册后可看大图

guessTest_2012_2_12_7_2_11.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-9-15 11:49:55 | 显示全部楼层
路过看一看有什么好东西收藏一下,强烈支持楼主ing……37743
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-9-15 13:57:23 | 显示全部楼层
:lol:路过看看
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-6 07:36

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表