-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpa_lab_4_2_7_(1)-A.cpp
40 lines (34 loc) · 955 Bytes
/
cpa_lab_4_2_7_(1)-A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include<math.h>
using namespace std;
bool is_close(double a, double b, double tolerance){
return (fabs(a-b) < tolerance);
}
int main(void) {
if (0.3 == 3 * 0.1) {
cout << "The numbers are equal";
} else {
cout << "The numbers are not equal";
}
cout << endl;
if (is_close(0.3, 3 * 0.1, 0.00000001)) {
cout << "The numbers are close enough";
} else {
cout << "The numbers are not close enough";
}
cout << endl;
// this should work regardless of the argument order
if (is_close(3 * 0.1, 0.3, 0.00000001)) {
cout << "The numbers are still close enough";
} else {
cout << "The numbers are not close enough";
}
cout << endl;
if (is_close(3 * 0.1, 0.31, 0.00000001)) {
cout << "The numbers are still close enough";
} else {
cout << "The numbers are not close enough";
}
cout <<endl;
return 0;
}