Error

Hello guys! I come to you to ask for help with an error that i do not understand.. if you could help it'd be great..
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
 #include <iostream>
#include <cmath>

using namespace std;

int convertdecimal(int n){

	int output=0;

	for(int i=0;n>0;i++){

				if(n%10==1){

						output+=pow(2,i);

						}

				n=n/10;

				}

	return output;

}
int main(){
	int a,b,c,d,a2=0, b2=0, count1=0, count2=0;
	cin>>a>>b;
	for(int i=0;a>0;i++){
				a2+=pow(10,i)*(a%2);
				a=a/2;
				count1++;
			}
	for(int i=0;b>0;i++){
				b2+=pow(10,i)*(b%2);
				b=b/2;
				count2++;
			}
cout<<a2<<" "<<b2<<" "<<endl;
	for(int i=0;a!=0 && b!=0;i++){
				if(a2/pow(10,(count1-1))== b2%10){
								b2=b2/10;
				 				a2=a2%(pow(10,(count1-1)));	
								}
				}
	
	c=convertdecimal(a2);
	d=convertdecimal(b2);
	cout<<c+d<<endl;	
	return 0;
}

This program is to calculate(first) the binary version of two variables and if the first digit of the first number is equal to the last digit of the second number we erase them from the numbers.. and so on until you don't erase anything else.... afterwards you put the remaining values back to decimal and display their sum.. The program is not that important as the error is ..

35:35: error: invalid operands of types ‘int’ and ‘__gnu_cxx::__promote_2<int, int>::__type {aka double}’ to binary ‘operator%’
Ifyou could help me solve this i would apreciate it.. thanks in advance!
as far as i know, pow() using double
Thank you very much for the help! i changed my code a little bit based on what you've made me realise but i got some logical problems...
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
#include <iostream>
#include <cmath>

using namespace std;

int convertdecimal(int n){

	int output=0;

	for(int i=0;n>0;i++){

				if(n%10==1){

						output+=pow(2,i);

						}

				n=n/10;

				}

	return output;

}
int main(){
	int a,b,c,d,a2=0, b2=0, count1=0, count2=0;
	cin>>a>>b;
	for(int i=0;a>0;i++){
				a2+=pow(10,i)*(a%2);
				a=a/2;
				count1++;
			}
	for(int i=0;b>0;i++){
				b2+=pow(10,i)*(b%2);
				b=b/2;
				count2++;
			}
	cout<<a2<<" "<<b2<<" "<<endl;
	while(1){
				if(a2/((int)pow(10,(count1-1)))== b2%10){
								b2=b2/10;
				 				a2=a2%((int)(pow(10,(count1-1))));
								count1--;
								cout<<a2<<" "<<b2<<" "<<endl;	
								}
				if(a2<=0 && b2<=0) break;
				}
	
	c=convertdecimal(a2);
	d=convertdecimal(b2);
	cout<<c+d<<endl;	
	return 0;
}

My biggest problem is that a2 is not updating correctly... If you can help i would thank a lot...
PS i also got one message on the console like"Floating point exception"
Topic archived. No new replies allowed.