Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Homeworks / homework1.cpp
diff options
context:
space:
mode:
Commite30eed631d2930570f5cc7355826c8854f3ac265 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-24 17:36:18 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-24 17:36:18 +0200
Files09312615db655e30bcc6dd190b2b4278ed3946cb /Year 1/Programming introduction/Homeworks/homework1.cpp
uni-projects-e30eed631d2930570f5cc7355826c8854f3ac265.tar
uni-projects-e30eed631d2930570f5cc7355826c8854f3ac265.tar.gz
uni-projects-e30eed631d2930570f5cc7355826c8854f3ac265.zip
Parent1c8ef83e8ce20bb71e81f678728eb29f5951e190 (diff)
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.cpp10
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 };