c - 用c猜数字程序

标签 c

我需要编写一个程序,当计算机选择从1到100的数字时,玩“猜数字”游戏,用户有10次尝试,如果他猜的数字太小,每轮用户都会收到输出或太大,或者是幸运数字,请帮忙

这就是我到目前为止所做的...

#include <stdio.h>
#include <stdlib.h>

void main() {


    int i ,guess=0 , lucky=rand()%100;
    for (i = 0; i <= 10; i++) {
        printf("please enter your guess\n");
        scanf("%d",&guess);



        }
}

最佳答案

这应该适合你!

#include <stdio.h>
#include <stdlib.h>

int main() {

    srand(time(NULL));
    int count , guess = 0, lucky = rand() % 101;


    for (count = 0; count < 10; count++) {
        printf("please enter your guess\n>");
        scanf("%d", &guess);

        if(guess == lucky) {
            printf("WIN");
            break;
        }

        if(guess > lucky)
            printf("too big\n\n");
        else
            printf("too small\n\n");

    }

    if(count == 10)
        printf("FAIL");


    return 0;

}

关于c - 用c猜数字程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26834437/

相关文章:

c++ - 编译时如何更改makefile诊断消息[GNU ARM GCC,Eclipse make.exe]

c++ - 如何帮助编译器根据输入的约束优化我的程序?

无法打开共享对象 cygmpfr-1.dll

c - ltrace printf() 但显示 puts()

链接 IF 句子与 IF 句子中的链接条件

Python - 将 PyInt 转换为 C int

C 到 MIPS 转换

c - 如何显示 sigusr1 和 sigusr2 的输出?

c - 为什么在一个函数中声明的 union 类型在另一个函数中使用是无效的?

c 开放式简历;如何将二维数组转换为 IplImage?