此代码/帮助中的错误 [英] errors in this code / help
本文介绍了此代码/帮助中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//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...
}
此代码和您的 ^ ]确实表明您正在尝试跑步,然后才能走路.花一些时间阅读课程笔记和C ++文档,直到您了解C ++的基本语法(包括数组,循环等)为止.
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, thear[]
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屋!
查看全文