From 2acfa5e78f4fab5c540f3798d7444b816c264e7f Mon Sep 17 00:00:00 2001 From: Greg King Date: Fri, 9 Nov 2018 17:11:03 -0500 Subject: [PATCH] Made div-test.c use doesclrscrafterexit(). It no longer waits for a key tap if it doesn't need to do that. Also, normalized the source code formatting. --- testcode/lib/div-test.c | 65 +++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/testcode/lib/div-test.c b/testcode/lib/div-test.c index 2d5c2541e..401f13ff8 100644 --- a/testcode/lib/div-test.c +++ b/testcode/lib/div-test.c @@ -2,37 +2,44 @@ ** ** This program tests the division and modulo operators ** and the div() library function. -** -** 2002-10-24, Greg King */ +#include +#include #include #include -#include -static bool test(int dividend, int divisor) { - div_t result; - - result = div(dividend, divisor); - printf("%+d/%+d= %+d, %+d%%%+d= %+d, div()= %+d, %+d\n", - dividend, divisor, dividend / divisor, - dividend, divisor, dividend % divisor, - result.quot, result.rem); - return result.quot * divisor + result.rem != dividend; - } - -int main(void) { - bool t; - - printf("\nTest of division and modulus operations:\n\n"); - t = test(+40, +3) || - test(+40, -3) || - test(-40, +3) || - test(-40, -3); - if (t) - printf("\nThe div() function made a wrong result!\n"); - - printf("\nTap a key, to exit. "); - getchar(); - return (int)t; - } +static bool test (int dividend, int divisor) +{ + div_t result; + + result = div (dividend, divisor); + printf ("%+d/%+d= %+d, %+d%%%+d= %+d, div()= %+d, %+d\n", + dividend, divisor, dividend / divisor, + dividend, divisor, dividend % divisor, + result.quot, result.rem); + + return result.quot * divisor + result.rem != dividend; +} + +int main (void) +{ + bool t; + + printf ("\nTest of division and modulus operations:\n\n"); + + t = test (+40, +3) || + test (+40, -3) || + test (-40, +3) || + test (-40, -3); + if (t) { + printf ("\nThe div() function made a wrong result!\n"); + } + + if (doesclrscrafterexit ()) { + printf ("\nTap the Return key to quit. "); + getchar (); + } + + return (int)t; +} -- 2.39.5