From e30eed631d2930570f5cc7355826c8854f3ac265 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 24 Nov 2021 17:36:18 +0200 Subject: Updated include comments and used fabs in eq of exercise 0 --- Year 1/Programming introduction/Homeworks/homework1.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Year 1/Programming introduction/Homeworks/homework1.cpp') diff --git a/Year 1/Programming introduction/Homeworks/homework1.cpp b/Year 1/Programming introduction/Homeworks/homework1.cpp index 7bef461..a986744 100644 --- a/Year 1/Programming introduction/Homeworks/homework1.cpp +++ b/Year 1/Programming introduction/Homeworks/homework1.cpp @@ -1,6 +1,6 @@ -#include -#include -#include // rand and srand for ex. 5 +#include // cin, cout +#include // fabs, sqrt +#include // rand, srand using namespace std; @@ -14,7 +14,7 @@ double const FLOAT_EPSILON = 0.001; bool eq(double a, double b) { - return ((a - b) < 0.0 ? (b - a) : (a - b)) < FLOAT_EPSILON; + return fabs(a - b) < FLOAT_EPSILON; } bool lt(double a, double b) @@ -218,7 +218,7 @@ int genSecretNum() { // Initializes random seed (required for getting a random number on every program launch) // Taken from included reference: https://www.cplusplus.com/reference/cstdlib/rand#example - srand (time(NULL)); + srand(time(NULL)); int rnd = rand(), result = 0; bool takenDigits[10] = { 0 }; -- cgit v1.3.1-23-gd82d