## Mak!zZz

Can someone help me with this problem
I need program in c++ ,that can sum number DIGIC COMPLEMENT and RADICAL COMPLEMENT
IF the input is in
DC
1111111111110101
0000000000100010
my output should be
0000000000011000

## Lucaci Andrew 140

What do you have so far?

## Labdabeta 182

Those links didn't work (at least not for me) please input them in a code block (just hit the "Code" button on the top of the editor). Also I have a feeling that your description of your problem will be insufficient. Try to clearly describe exactly what you are trying to do.

## Labdabeta 182

In his first post he did say that it was about the different compliment systems (he misspelled them but he meant Digit and Radix complements) Digit complement in binary is 1s complement, whereas radix complement in binary is 2s complement. Here is -3 stored in a 3-bit number in both:

Digit complement (1s complement):
original is 011 (3), invert all bits to get 100 (-3)

original is 011 (3), most significant bit is negative so 111 is -1, so 101 would be -3 (by subtracting the 2 bit)

The issue is that I can't access his code. If you can could you post it directly here rather than using pastebin?

## ddanbe 2,724

@Labdabeta Thanks for the clarification. As I'm not native English myself, I found the OP used a rather "weird syntax"

## Mak!zZz

This is my code, in C, and i have 4 mistakes, can you please check out this code and tell me where are the mistakes. http://imgur.com/M4xQonA
Where it writes "HE" this that is wrong
Thanks

``````#include <stdio.h>
#include <math.h>
#include <string.h>

`int main() {`
int a,i=0,y=0,x=0,sum=0,sum1=0,n,prom;
int b,b1,zbor,new;
char aa,st;

//printf("Sistem: ");
while(y<=2&&(aa=getchar())!='\n') {
st[y]=aa;
y++;
}
st[y]=0;

//printf("Prv binaren broj: ");
while(i<20&&(a=getchar())!='\n') {
b[i]=a;
i++;
++x;
}
if(st=='D'&&st=='C') {
for(i=0; i<x; i++) {
if(b[i]-48==1) b[i]=0;
if(b[i]-48==0) b[i]=1;
}

//printf("Komplement: ");
//for(i=0;i<x;i++)
//printf("%d",b[i]);

//printf("\n");

for(i=x; i>=0; i--)
if(b[i]) sum+=pow(2,x-i-1);
}

if(st=='R'&&st=='C') {
for(i=x; i>=0; i--)
if(b[i]-48) sum+=pow(2,x-i-1);
}
i=0;
x=0;
//printf("Vtor binaren broj: ");
while(i<20&&(a=getchar())!='\n') {
b1[i]=a;
i++;
++x;
}
if(st=='D'&&st=='C') {
for(i=0; i<x; i++) {
if(b1[i]-48==1) b1[i]=0;
if(b1[i]-48==0) b1[i]=1;
}

//printf("Komplement: ");
//for(i=0;i<x;i++)
//printf("%d",b1[i]);

for(i=x; i>=0; i--)
if(b1[i]) sum1+=pow(2,x-i-1);
}

if(st=='R'&&st=='C') {
for(i=x; i>=0; i--)
if(b1[i]-48) sum1+=pow(2,x-i-1);
}

//printf("\n");

//printf("Prv broj - decimalna vrednost: %d\n",sum);
//printf("Vtor broj - decimalna vrednost: %d\n",sum1);

i=0;
x=0;
n=sum+sum1;
prom=n;
//printf("Zbir: %d\n",n);

while(n!=0) {
a=n%2;
new[i]=a;
if (a==0) zbor[i]=1;
if (a==1) zbor[i]=0;
i++;
n=n/2;
++x;
}

if(st=='D'&&st=='C') {
//printf("Komplement: ");
for(i=x; i>0; i--) {
printf("%d",zbor[i-1]);
}
}

if(st=='R'&&st=='C') {
if (prom==42445) printf("overflow");
else{
for(i=16;i>x;i--)
printf("0");

for(i=x;i>0;i--)
printf("%d",new[i-1]);
}
}

//printf("\n");
sum=0;
for(i=x; i>=0; i--) {
if(new[i-1]) sum+=pow(2,x-i-1);
}

/*if(st=='D'&&st=='C') {
printf("Komplement: ");
for(i=x; i>0; i--) {
printf("%d",zbor[i-1]);
}
}*/

printf("\n");

return 0;
}
``````

## Labdabeta 182

Some descriptive comments (in english) would be very helpful. Your variable names are hard to decode. Rename your variables so that they explain what they are, and use comments to describe your code. Also I would strongly recommend splitting your code into functions, for more legibility.