zoukankan      html  css  js  c++  java
  • C语言 猜字游戏

    #include <time.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    
    main()
    {
        char c;
        clock_t start, end;
        time_t a, b;
        double var;
        int i, guess;
        int YY;
        srand(time(NULL));
        printf("do you want to play it.('y' or 'n') \n");
    loop:
        while((c=getchar()) == 'y')
        {
            i = rand()%100;
            YY = 1;
            printf("\nPlease input number you guess:\n");
            start = clock();
            a = time(NULL);
            scanf("%d", &guess);
     
            while(guess!=i)
            {
                printf("%d %c\n", guess, guess);
    
                if(guess>i)
                {
                    printf("please input a little smaller.\n");
                    if(!scanf("%d", &guess)){YY = 0;break;};
    
                }
                
                else
                {
                    
                    printf("please input a little bigger.\n");
                    if(!scanf("%d", &guess)){YY = 0;break;};
                }
            }
            end = clock();
            b = time(NULL);
            printf("\1: It took you %6.3f seconds\n", var=(double)(end-start)/1000);
            printf("\1: It took you %6.3f seconds\n\n", difftime(b, a));
            if(YY == 0)
            {
                printf("input data type error!");
    
            }
            else if(var < 15 && YY == 1)
    
            {
                printf("\1\1 You are vary clever! \1\1\n\n");
                
            }
            else if(var < 25 && YY == 1)
            {
                printf("\1\1 you are normal! \1\1\n\n");
    
            }
            else
            {
                printf("\1\1 you are stupid!\1\1\n\n");
            
            }
            if(YY == 1)
            {
                printf("The number you guess is %d", i);
            }
            
        }
        printf("\nDo you want to try t again?(\"y\".or.\"n\")\n");
        if((c=getch()) == 'y')
            goto loop;
    }

    http://www.pythonschool.com/python/6.html 转摘

  • 相关阅读:
    shell的正则表达式
    shell语法
    shell通配符
    shell小命令
    DNS
    CCNA参考链接
    Network problem solving flow chart
    我是一个路由器
    我是一个网卡
    Chrome
  • 原文地址:https://www.cnblogs.com/pythonschool/p/2729276.html
Copyright © 2011-2022 走看看