using % in c++

hi.. i was making a program that inputs 3 integers and makes the user select a certain operator.. then after that i need it to determine if the total is an even or an odd number..

the problem is.. im having trouble in determining if the total is even or odd.. when i run the program it says that " '%' : illegal, left operand has typed double "

heres the code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
char Operator;
	double a, b, c;
	double output;
	double ANS;
	cout<<"Enter 3 integers: \n\n";
	cin>>a>>b>>c;
	cout<<"Select operator: Enter M for *, D for /, A for +, S for -\n";
	cin>>Operator;
	if(Operator == 'M')
		output = a * b * c;
	if(Operator == 'D')
		output = a / b / c;
	if(Operator == 'A')
		output = a + b + c;
	if(Operator == 'S')
		output = a - b - c;
	cout<<"The total is " <<output<<endl;

	ANS=(output%2);
		if(ANS==0)
			cout<<"The total is even!";
		else
			cout<<"The total is odd!";


please help.. is the declaration for variable ANS right?? if not.. what should i use?
Last edited on
you cant use the % operator with doubles, use an int instead or if in some case you really do need to do a modulus on a floating point value use fmod().
ah.. i see.. tnx for the help.. the int did work.. :)
Topic archived. No new replies allowed.