diff options
| -rw-r--r-- | src/calculer.c | 31 | 
1 files changed, 30 insertions, 1 deletions
| diff --git a/src/calculer.c b/src/calculer.c index b1de0a4..1c78197 100644 --- a/src/calculer.c +++ b/src/calculer.c @@ -18,10 +18,39 @@  #include "config.h"  #include <stdio.h> +#include <stdlib.h> +#include <readline/readline.h> + +static int lower = 0; +static int upper = 100; + +/* Return a random number x such that lower <= x < upper. */ +int +calculer_rand() +{ +	return lower + rand()%(upper-lower); +}  int  main(void)  { -	printf("%s\n", PACKAGE_STRING); +	char prompt[31] = {0}; +	int x, y, res; +	char *input; + +	while (1) +	{ +		x = calculer_rand(); +		y = calculer_rand(); +		res = x+y; +		sprintf(prompt, "%d + %d = ", x, y); +		input = readline(prompt); + +		if (atoi(input) == res) +			printf("RIGHT\n"); +		else +			printf("WRONG\n"); +	} +  	return 0;  } | 
