From a588d8f8d080d644bca63ce96840dd0126cc117f Mon Sep 17 00:00:00 2001 From: matyushev_mo Date: Wed, 25 Feb 2026 19:50:23 +0300 Subject: [PATCH] LAB2: bounds-safe W reading --- src/LAB2.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/LAB2.c b/src/LAB2.c index 0663998..908661d 100644 --- a/src/LAB2.c +++ b/src/LAB2.c @@ -15,8 +15,20 @@ void lab_2() printf("Enter [W_min]: "); READ_EXACT("%lf", w_min); - printf("Enter [W_max]: "); - READ_EXACT("%lf", w_max); + do + { + printf("Enter [W_max]: "); + READ_EXACT("%lf", w_max); + + if (w_max < w_min) + { + printf("W_max cannot be less than W_min, try again\n"); + continue; + } + + break; + } + while (1); printf("Enter [d]: "); READ_EXACT("%d", d);