do while 循环结构冲突

来源:百度知道 编辑:UC知道 时间:2024/06/08 12:30:21
// 串行加法器.cpp : Defines the entry point for the console application.
//

#include<iostream>
using namespace std;

void main()
{
char A[9],B[9],C[9]={'0'},S[9];
int i=0;
char m;
cout<<"Please input an 8-byte-binary digital A:"<<endl;
do{
cin>>m;
if(m=='1'||m=='0')
{
A[i]=m;
i++;
}
}while(i<8);
cout<<"1,That's the binary digital you have input A:"<<endl;
for(i=0;i<8;i++)
cout<<A[i];
cout<<endl;
cout<<"Please input another 8-byte-binary digital B:"<<endl;
do{
cin>>m;
if(m=='1'||m=='0')
{
B[i]=m;
i++;
}
}while(i<8);
cout<<"2,That's the binary digital you have inpu

第二个while循环之前要把i值赋为0

你在第一个for循环之后
for(i=0;i<8;i++)
cout<<B[i];
i的值变为了8后面的while循环不能继续,所以得不到你想的值,就在while循环之间再次给i赋值为了0