diff options
author | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2024-05-30 22:02:36 +0900 |
---|---|---|
committer | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2024-05-30 22:02:36 +0900 |
commit | e13cc00a7fba5802f9efa555b67ad2cc24c2e6e0 (patch) | |
tree | db11a7120954e5fd06f7e9960e060dfe33dcdec7 /src | |
parent | 4e5b63956f80983b97db3ba5020c64c3cd695202 (diff) |
Make a minimal working program
Diffstat (limited to 'src')
-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; } |