-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_calculator.cpp
87 lines (68 loc) · 2.33 KB
/
basic_calculator.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/********************************************
date: "17.10.2022"
authors: "DmitrijP1402"
filename: "basic_calculator.cpp"
********************************************/
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int calculationType = 0;
float firstNumber = 0;
float secondNumber = 0;
cout << " Basic Calculator" << endl;
while (true)
{
cout << endl; //Output for calculation
cout << " plus = 1, minus = 2, multiplied = 3, divided = 4, root = 5, squared = 6" << endl;
cout << " enter the calculation type: ";
cin >> calculationType;
cout << " enter first number: ";
cin >> firstNumber;
if ( calculationType != 5) //enter second number if calculationType is not root
{
cout << " enter second number: ";
cin >>secondNumber;
cout << endl;
cout << " result:" << endl;
}
if (calculationType == 1) //plus
{
cout << " " << firstNumber << " + " <<secondNumber << " = ";
cout << firstNumber +secondNumber << endl;
}
if (calculationType == 2) //minus
{
cout << " " << firstNumber << " - " <<secondNumber << " = ";
cout << firstNumber -secondNumber << endl;
}
if (calculationType == 3) //multiplied
{
cout << " " << firstNumber << " * " <<secondNumber << " = ";
cout << firstNumber*secondNumber << endl;
}
if (calculationType == 4) //divided
{
cout << " " << firstNumber << " : " <<secondNumber << " = ";
cout << firstNumber /secondNumber << endl;
}
if (calculationType == 5) //root
{
cout << endl;
cout << " sqrt(" << firstNumber << ")" << " = ";
cout << sqrt(firstNumber) << endl;
}
if (calculationType == 6) //squared
{
float squaredResult = 0;
squaredResult = firstNumber;
for (int forLoopNumber = 0; forLoopNumber <secondNumber - 1; forLoopNumber++)
{
squaredResult = firstNumber * squaredResult;
}
cout << " " << firstNumber << "^" <<secondNumber << " = " << squaredResult;
cout << endl;
}
}
}