- 论坛徽章:
- 0
|
如何使局部变量生效!!!
#include<iostream.h>;
void main()
{
const int num=10;
int interval;
int a[num];
for(int i=0;i<num;i++)
a=i+1;
cout<<"pls input the interval";
cin>;>;interval;
for(int i=0;i<num;i++)
cout<<a<<",";
cout<<endl;
int k=1;
int i=-1;
{while(1)
for(int j=0;j<interval
{
i=(i+1)%num;
if(a!=0)
j++;
}
if(k==num)break;
cout<<a<<",";
a=0;
k++;
}
cout<<"\nNo."<<a<<"boy's won.\n";
}
: error C2374: 'i' : redefinition; multiple initialization
而改动后就没有错误:
#include<iostream.h>;
void main()
{
const int num=10;
int interval;
int a[num];
{for(int i=0;i<num;i++)
a=i+1;
cout<<"pls input the interval";
cin>;>;interval;}
{for(int i=0;i<num;i++)
cout<<a<<",";
cout<<endl;
}
int k=1;
int i=-1;
{while(1)
{for(int j=0;j<interval
{
i=(i+1)%num;
if(a!=0)
j++;
}
if(k==num)break;
cout<<a<<",";
a=0;
k++;
}}
cout<<"\nNo."<<a<<"boy's won.\n";
} |
|