鱼C论坛

 找回密码
 立即注册
查看: 3576|回复: 7

[技术交流] 哪位大哥帮我看下哪里错了

[复制链接]
发表于 2012-7-12 21:09:55 | 显示全部楼层 |阅读模式
1鱼币
#include <stdio.h>
#include <time.h>
#include <stdl ib.h>
void main()
{
int num,x ,count;
srand((unsigned)time(NULL));
loop: count = 0;
   num = rand()%100+1;
   printf("电脑已产生一个随机数\n");
   while(1){count++;
   printf("请输入你猜的数: ");
    scanf("%d", &x);
   if(x=num){if(count<7) {printf("congratulation\n");
   goto loop; }
   else if(count<15){printf("bet you do it better\n");
   goto loop;}
   else{exit(0);
   }break;}
   else if(x<num)printf("your answer is low, try again\n");
   elseprntf("your answer is high, try again\n");}
}

最佳答案

查看完整内容

#include #include #include void main() { int num, x, count; srand((unsigned)time(NULL)); loop: count = 0; num = rand()%100+1; printf("电脑已产生一个随机数\n"); while(1) { count++; printf("请输入你猜的数: "); scanf("%d", &x); if(x == num) { if(count
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-7-12 21:09:56 | 显示全部楼层
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void main()
{
        int num, x, count;
        srand((unsigned)time(NULL));
loop: count = 0;
          num = rand()%100+1;
          printf("电脑已产生一个随机数\n");
          while(1)
          {
                  count++;
                  printf("请输入你猜的数: ");
                  scanf("%d", &x);
                  if(x == num)
                  {
                          if(count<7)
                          {
                                  printf("congratulation\n");
                                  goto loop;
                          }
                          else if(count<15 && count >= 7 )
                          {
                                  printf("bet you do it better\n");
                                  goto loop;
                          }
                          else
                          {
                                  exit(0);
                          }
                          break;  
                  }
                  else if(x < num)
                          printf("your answer is low, try again\n");
                  else
                          printf("your answer is high, try again\n");}
}

不知道你是不是这个意思
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2012-7-12 21:33:57 | 显示全部楼层
目测有一行分号是国标的
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2012-7-12 21:47:00 | 显示全部楼层
你想要实现什么啊?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2012-7-12 22:22:38 | 显示全部楼层
帮你优化了一下

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void main()
{
          int num,x,count;
          srand((unsigned)time(NULL));
loop: count = 0;
          num = rand()%100+1;
          printf("电脑已产生一个随机数\n");
          while(1)
          {
                  count++;
                  printf("请输入你猜的数: ");
                  scanf("%d", &x);
                  if(x==num)
                  {
                          if(count<7)
                          {
                                  printf("congratulations\n");
                                  break;
                          }
                          else
                          {
                                  printf("bet you do it better\n\n\n再重新来一次吧(*^__^*) 嘻嘻……\n\n\n");
                                  goto loop;
                          }
                          
                  }
                  else if(x<num)
                          printf("your answer is low, try again\n");
                  else
                          printf("your answer is high, try again\n");
          }
}


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

使用道具 举报

发表于 2012-7-12 22:49:23 | 显示全部楼层
没怎么喜欢用GOTO 语句
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2012-7-14 16:22:02 | 显示全部楼层
goto是必须品, 有汇编在就有goto在.
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2012-7-14 16:56:12 | 显示全部楼层
if(x=num)改成 if(x==num)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-9-21 02:36

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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