鱼C论坛

 找回密码
 立即注册
查看: 1059|回复: 3

[已解决]代码出错

[复制链接]
发表于 2020-8-24 11:13:02 | 显示全部楼层 |阅读模式

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

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

x
  1. int main

  2. {

  3. srand(time(0));
  4. int number=rand()%100+1;
  5. int count=0;
  6. int a=0;
  7. do{

  8.         printf("请猜这个1到100之间的数。");
  9.         scanf("%d",&a);
  10.         count++;
  11.         if (a>number){
  12.                 printf("你猜的数大了。");
  13.         }else if(a<number){
  14.                 printf("你猜的数小了。");
  15.         }
  16. }while(a!=number);
  17. printf("太好了,你用了%d次就猜到了答案。\n",count);
复制代码
最佳答案
2020-8-24 11:20:39


试试这样呢?不怎么会 C ,你的 main 忘记加上 () 括号了,最后也忘记设置 return 了

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>

  4. int main() {

  5.     srand(time(0));
  6.     int number = rand() % 100 + 1;
  7.     int count = 0;
  8.     int a = 0;
  9.     do {

  10.         printf("请猜这个1到100之间的数。");
  11.         scanf("%d", &a);
  12.         count++;
  13.         if (a > number) {
  14.             printf("你猜的数大了。");
  15.         } else if (a < number) {
  16.             printf("你猜的数小了。");
  17.         }
  18.     } while (a != number);
  19.     printf("太好了,你用了%d次就猜到了答案。\n", count);

  20.     return 0;
  21. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-24 11:20:39 | 显示全部楼层    本楼为最佳答案   


试试这样呢?不怎么会 C ,你的 main 忘记加上 () 括号了,最后也忘记设置 return 了

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>

  4. int main() {

  5.     srand(time(0));
  6.     int number = rand() % 100 + 1;
  7.     int count = 0;
  8.     int a = 0;
  9.     do {

  10.         printf("请猜这个1到100之间的数。");
  11.         scanf("%d", &a);
  12.         count++;
  13.         if (a > number) {
  14.             printf("你猜的数大了。");
  15.         } else if (a < number) {
  16.             printf("你猜的数小了。");
  17.         }
  18.     } while (a != number);
  19.     printf("太好了,你用了%d次就猜到了答案。\n", count);

  20.     return 0;
  21. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-24 11:26:02 | 显示全部楼层
没有包含头文件吧?

  1. #include "stdio.h"
  2. #include "windows.h"
  3. #include <time.h>
  4. int main()

  5. {
  6.        
  7.         srand(time(0));
  8.         int number=rand()%100+1;
  9.         int count=0;
  10.         int a=0;
  11.         do{
  12.                
  13.         printf("请猜这个1到100之间的数。");
  14.         scanf("%d",&a);
  15.         count++;
  16.         if (a>number){
  17.                         printf("你猜的数大了。");
  18.         }else if(a<number){
  19.                         printf("你猜的数小了。");
  20.         }
  21.         }while(a!=number);
  22.         printf("太好了,你用了%d次就猜到了答案。\n",count);
  23.         return 0;
  24. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-24 11:26:23 | 显示全部楼层
Twilight6 发表于 2020-8-24 11:20
试试这样呢?不怎么会 C ,你的 main 忘记加上 () 括号了,最后也忘记设置 return 了

刚学没几天,就学着敲,开学要考555
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-6 00:17

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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