diff --git a/src/userinput.c b/src/userinput.c index 98fc020..393633e 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -147,6 +147,35 @@ bool isNumberValid(long double value, long double *min, long double *max, long d return true; } +void printInvalidNumberMessage(long double value, long double *min, long double *max, long double *greaterThan, long double *smallerThan, long double leftBorder, long double rightBorder) { + printText("Ungueltige Eingabe! Fuer die eingegebene Zahl muss gelten:"); + if (min != NULL) { + printText(" >="); + printlf(*min); + } + if (max != NULL) { + printText(" <="); + printlf(*max); + } + if (greaterThan != NULL) { + printText(" >"); + printlf(*greaterThan); + } + if (smallerThan != NULL) { + printText(" <"); + printlf(*smallerThan); + } + if (min == NULL && greaterThan == NULL) { + printText(" >="); + printlf(leftBorder); + } + if (max == NULL && smallerThan == NULL) { + printText(" <="); + printlf(rightBorder); + } + printText("\n"); +} + long double getNumber(char *message, long double *min, long double *max, long double *greaterThan, long double *smallerThan, long double leftBorder, long double rightBorder) { while (true) { char *input = gets(message, NULL, NULL); @@ -166,32 +195,7 @@ long double getNumber(char *message, long double *min, long double *max, long do if (isNumberValid(number, min, max, greaterThan, smallerThan, leftBorder, rightBorder)) { return number; } - printText("Ungueltige Eingabe! Fuer die eingegebene Zahl muss gelten:"); - if (min != NULL) { - printText(" >="); - printlf(*min); - } - if (max != NULL) { - printText(" <="); - printlf(*max); - } - if (greaterThan != NULL) { - printText(" >"); - printlf(*greaterThan); - } - if (smallerThan != NULL) { - printText(" <"); - printlf(*smallerThan); - } - if (min == NULL && greaterThan == NULL) { - printText(" >="); - printlf(leftBorder); - } - if (max == NULL && smallerThan == NULL) { - printText(" <="); - printlf(rightBorder); - } - printText("\n"); + printInvalidNumberMessage(number, min, max, greaterThan, smallerThan, leftBorder, rightBorder); } }