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 "
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?
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().