-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaths-calculations-4.cpp
57 lines (46 loc) · 1.26 KB
/
maths-calculations-4.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
/*
* Mathematics calculations
*/
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
//Declare variables
double x, z;
char variant;
//Get the variant
cout << "Enter a variant (options: a, b or c): ";
cin >> variant;
//Get the value of x from the user
cout << "Enter value of x: ";
cin >> x;
switch (variant)
{
//Actions of case a
case 'a':
z = sin(pow(x, 5));
cout << "Variant = " << variant << "; X = " << x << "; Z = " << z << endl;
break;
//Action of case b
case 'b':
if (x > 0) // must be greater than 0 to proceed
{
z = log(x);
cout << "Variant = " << variant << "; X = " << x << "; Z = " << z << endl;
}
else
cout << "Variant = " << variant << "; X = " << x << " cannot be calculated" << endl;
break;
//Action of case c
case 'c':
z = pow(x, 3);
cout << "Variant = " << variant << "; X = " << x << "; Z = " << z << endl;
break;
//Case if variant is not described above
default:
cout << "Invalid variant: " << variant << endl;
break;
}
return 0;
}