Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
//sum of two 5 bit  binary 

int ar1[ 5 ]; 
int ar2[5];
int ar3[6];
int i;
for (  i=0; i<5; i++) 
cin>>ar[i];
for (  i=0; i <5; i++)
cin>>ar1[i];
{
ar2[i] = ar[i] + ar1[i] + ar3[i];
if ( ar2[i] > 1)
{
ar3[i+1] = 1;
ar2[i] %= 2;
}
cout<<ar2[i]<<endl;}
return 0;
Posted
Updated 24-May-11 10:53am
v2
Comments
Manfred Rudolf Bihy 25-May-11 10:21am    
REPOST!

You don't seem to understand why brackets are there...

loop with one statement:
for(int i=0; i<5;i++)
  x=i;

loop with more than one statement:
for(int i=0; i<5;i++)
{           //<-- More than one statement, must include brackets to keep it inside of statement
  x=i;
  y= x+5;
  //etc...
}
 
Share this answer
 
Comments
Valery Possoz 24-May-11 17:39pm    
I find it's quite funny that last week survey was about brackets!
http://www.codeproject.com/Surveys/1156/Do-you-wrap-single-line-statements-in-braces-or-be.aspx
Albert Holguin 24-May-11 23:46pm    
it's ironic isn't it?
This code and your previous question[^] really shows that you are trying to run before you can walk. Spend some more time reading your course notes and C++ documentation until you can understand the basic syntax of C++ including arrays, loops etc.
 
Share this answer
 
In addition to above responses, in your code, the ar[] array was not declared with a particular data type, before been used. Also, check the use of brackets before the second "for" loop.



One of the qualities of a good programmer is patience!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900