diff options
Updated include comments and used fabs in eq of exercise 0
1 files changed, 5 insertions, 5 deletions
| -rw-r--r-- | Year 1/Programming introduction/Homeworks/homework1.cpp | 10 |
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 <iostream> -#include <cmath> -#include <stdlib.h> // rand and srand for ex. 5 +#include <iostream> // cin, cout +#include <cmath> // fabs, sqrt +#include <stdlib.h> // 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 }; |
