-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.cpp
62 lines (55 loc) · 1.37 KB
/
calc.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
#include <iostream>
using namespace std;
int multiply(int first_num,int second_num){
int result=0, i=0;
while(i<second_num){
result+=first_num;
i++;
}
return result;
}
int divide(int first_num,int second_num){
int result=0;
while(first_num>=second_num){
first_num+=~second_num+1;
result++;
}
return result;
}
int main(){
//Get our variables defined
char operation;
int first_num;
int second_num;
int result;
//Get user input
cout << "Possible operations: '+' is additon '-' is subtraction '*' is multiplication and '/' is division" << endl;
cout << "Enter operation:" << endl;
cin >> operation;
cout << "Enter first number:" << endl;
cin >> first_num;
cout << "Enter second number:" << endl;
cin >> second_num;
//calculations
switch(operation){
case'+':
result = first_num + second_num;
break;
case'-':
//squiggle 1's complments a number. Basically making it turn from a 5 for example to -6. Just add 1 and we get the negative form of the original number
result = first_num + ~second_num + 1;
break;
case'*':
result = multiply(first_num,second_num);
break;
case'/':
result = divide(first_num,second_num);
break;
default:
cout << "you broke something." << endl;
break;
}
cout << result << endl;
//Checking second_num due to float input issues
//cout << "Second_num is:" << second_num << endl;
}