#include <stdio.h>

int getnumber(char prompt[], int imin, int imax, int repeat) {
    int i, n;

    for (i = 0; repeat <= 0 || i < repeat; ++i) {
        printf("%s", prompt);
        if (scanf("%d", &n) != 1 || n < imin || n > imax) {
            printf("Wrong input. Correct range [%d, %d].\n",
                   imin, imax);
            while (getchar() != '\n')
                ;
        }
        else return n;
    }

    return imin - 1;
}

