๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ ๋ณด์•ˆ·์ทจ์•ฝ์ /๐Ÿ”ธ์‹œ์Šคํ…œ·์šด์˜์ฒด์ œ

[Python] quizmachine ํ’€์ด

by Jenny:! 2022. 8. 12.

์•„๋ž˜๋Š” quizmachine.c ํŒŒ์ผ์ด๋‹ค.

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define DELAY 5

int main(){
	srand(time(NULL));
	int random1 = 0; //์ˆซ์ž1
	int random2 = 0; //์ˆซ์ž2
	int result = 0; //๊ฒฐ๊ณผ
	time_t t1, t2; //์‹œ๊ฐ„1, ์‹œ๊ฐ„2
	printf("Answer the 20 questions, then you can get a flag\n");
	for (int i=0; i<20; i++){ //20๋ฒˆ ๋ฐ˜๋ณต
		time(&t1);
		random1 = rand() % 101; //์ˆซ์ž1 ๋žœ๋ค
		random2 = rand() % 101; //์ˆซ์ž2 ๋žœ๋ค

		printf("%d + %d = \n",random1,random2);//์ˆซ์ž ๋‘๊ฐœ๋ฅผ ๋”ํ•ด์„œ ํ”„๋ฆฐํŠธ
		scanf("%d",&result); //๊ฒฐ๊ณผ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค
		time(&t2);
		if(difftime(t2,t1)>DELAY){ //t1๋ถ€ํ„ฐ t2 ์ฐจ์ด๊ฐ€ 5๋ณด๋‹ค ํฌ๋ฉด
			printf("time out!!!!!");//time out!!!!!
			return 0;
		}
		else if(result!=random1+random2){ //์˜ค๋‹ต์ด๋ฉด
			printf("wrong!!!\n"); //Wrong!!!
			return 0;
		}
	}
	printf("Success!!!\n"); //20๋ฒˆ ๋๋‚˜๋ฉด ์„ฑ๊ณต
}



 

ํŒŒ์ด์ฌ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ๋‹ค.

 

 

c ํŒŒ์ผ์„ ์‹คํ–‰ ํŒŒ์ผ๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.

์„ฑ๊ณต ๋ฉ”์‹œ์ง€๊ฐ€ ๋œฌ๋‹ค.