From 1e3bcb176cd48f7ecf844b0aea470278194df98c Mon Sep 17 00:00:00 2001 From: Jens Staal Date: Mon, 15 Jun 2020 06:27:45 +0200 Subject: [PATCH] simplify round() --- sources/sudoku.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/sources/sudoku.c b/sources/sudoku.c index 88308b8..b70232e 100644 --- a/sources/sudoku.c +++ b/sources/sudoku.c @@ -25,19 +25,12 @@ NOTE: This program is only made for entertainment porpuses. The puzzles are gene /* I hope this is approximately right */ int round(float x) { - int y=(int) x; - int z; + int y; if(x > 0) - if(x-y > 0.5) - z = (int)(x + 0.5); - else - z = y; - if(x<0) - if(x-y < -0.5) - z = (int)(x -0.5); - else - z = y; - return z; + y = (int)(x + 0.5); //int will round down, so if the decimal of x is .5 or higher this will round up. + else if(x < 0) + y = (int)(x - 0.5); // the same but opposite + return y; } #endif