此代码/帮助中的错误 [英] errors in this code / help

查看:78
本文介绍了此代码/帮助中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//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;

推荐答案

您似乎不明白为什么会有括号...

一条语句循环:
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...
}


此代码和您的
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.


除了上面的回答外,在代码中,在使用数组之前,未使用特定的数据类型对其进行声明.另外,请在第二个"for"循环之前检查方括号的使用.



优秀的程序员的素质之一就是耐心!
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!


这篇关于此代码/帮助中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆