C言語 clock ゲーム

 

#include <time.h>

#include <stdio.h>

#include <stdlib.h>

 

int main(void) {

    // insert code here...

   

    int a,b,c;

    int x;

    clock_t start, end;

    double req_time;

    

    srand(time(NULL));

    

    a = 100 + rand() % 900;

    b = 100 + rand() % 900;

    c = 100 + rand() % 900;

    

    printf("%d + %d + %dは何ですか:\n", a, b, c);

    

    start = clock(); /* 計測開始 */

    

    while(1) {

        scanf("%d", &x);

        if(x == a + b + c)

            break;

        printf("違います!\n");

    }

    

    end = clock(); /* 計測終了 */

    

    req_time = (double)(end - start) / CLOCKS_PER_SEC;

    

    printf("%.f秒かかりました。\n",req_time);

    

    if(req_time > 30.0)

        printf("遅っ\n");

    else if(req_time > 17.0)

        printf("まあまあ\n");

    else

        printf("合格\n");

    

    return(0);

    

   }