-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaths-calculations-1.cpp
59 lines (49 loc) · 1000 Bytes
/
maths-calculations-1.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Mathematics calculations
*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// Declare variables
double x, y, xmin, xmax, dx;
// Take inputs
cout << "Input xmin, xmax, dx\n";
cin >> xmin >> xmax >> dx;
cout << " while loop \n";
// Set x to minimum
x = xmin;
// Start while loop
while (x <= xmax)
{
// Check for positive numbers
if (x > 0) {
// Calculate
y = pow(log(x), 3);
// Output data
cout << "At x= " << x << " \t y= " << y << endl;
}
else
// Show error if x is negative
cout << "At x= " << x << " \t y = error\n";
x += dx; // increment x by delta x
}
// Start do while loop
cout << " \n do... while loop \n";
x = xmin;
do {
if (x > 0)
{
// Calculate
y = pow(log(x), 3);
cout << "At x= " << x << " \t y= " << y << endl;
}
else
// Show error if x is negative
cout << "At x= " << x << " \t y = error\n";
x += dx; // Increment x by delta x
} while (x <= xmax);
puts("OK!");
return 0;
}