add range check
This commit is contained in:
18
src/LAB3.c
18
src/LAB3.c
@@ -44,7 +44,7 @@ double do_while_fn(Context* ctx)
|
||||
r += iter_fn(ctx->x, i);
|
||||
++i;
|
||||
}
|
||||
while (i <= ctx->i);
|
||||
while (i <= ctx->n);
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -57,8 +57,20 @@ void lab_3()
|
||||
printf("Enter [x]: ");
|
||||
READ_EXACT("%lf", ctx.x);
|
||||
|
||||
printf("Enter [N]: ");
|
||||
READ_EXACT("%u", ctx.n);
|
||||
do
|
||||
{
|
||||
printf("Enter [N]: ");
|
||||
READ_EXACT("%u", ctx.n);
|
||||
|
||||
if (ctx.n < ctx.i)
|
||||
{
|
||||
printf("N could not be less than I=1, try again\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
while(1);
|
||||
|
||||
LoopFn* loop_fn;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user