From e13cc00a7fba5802f9efa555b67ad2cc24c2e6e0 Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Thu, 30 May 2024 22:02:36 +0900 Subject: Make a minimal working program --- src/calculer.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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 +#include +#include + +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; } -- cgit v1.2.3