Calculator Program errors

closed account (Ebf21hU5)
I have several errors in this program. I'm having trouble using static_cast.
Can someone please help me use static_cast in this program. I'm completely clueless.
Here is my program:

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
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>

using namespace std;

int main()
{
	double Op1, Op2, result;
	char Operator;
	
	cout << "This program is used to calculate numerical expressions." << endl;
	cout << "If you wish to continue, please enter a number, an operator, and another number " << endl;
	cin >> Op1 >> Operator >> Op2;

	
	if (Operator == '+')			
		result = Op1+Op2;
	else if (Operator == '-')		
		result = Op1-Op2;
	else if (Operator == '*')		
		result = Op1*Op2;
	else if (Operator == '/')		
		result = Op1/Op2;
	int Operator = static_cast<int>(Op1);
	else if (Operator == "div")
		result = Op1/Op2;
	int Operator = static_cast<int>(Op1);
	else if (Operator == "mod")
		result = fmod(Op1,Op2);
	else if (Operator == '^')		
		result = pow(Op1,Op2);
	else if (Operator == '%')
		result = (Op1/Op2)*100;
		
	cout << "The answer is " << result << endl;
	

	system("pause>nul");
	return 0;


why are you doing this following part of code...?
1
2
3
4
5
6
int Operator = static_cast<int>(Op1);
else if (Operator == "div")
	result = Op1/Op2;
int Operator = static_cast<int>(Op1);
else if (Operator == "mod")
	result = fmod(Op1,Op2);
Topic archived. No new replies allowed.