【发布时间】:2014-07-01 20:48:05
【问题描述】:
一个程序询问 10 个正整数并将它们分类为奇数或偶数正整数输入。该算法必须捕获负整数输入。输出将显示在两列中。奇数和偶数。
那么如何捕捉否定并通知无效输出呢?还是重新提示直到捕获到一个正数?
这是我的程序代码...
int x=10;
int a[x];
cout<<"Input :";
cin>>a[x];
while(a[x]!<0) /*[Error] expected ')' before '!' token*/
{ /*[Error] expected primary-expression before '<' token*/
if(a[x]<0) /*[Error] expected ';' before ')' token*/
{ /*[Error] expected '}' at end of input*/
cout<<"The input is negative try again";
cout<<"Input:";
cin>>a[x];
}
else
{
a[x++];
}
}
cout<<"ODD\tEVEN";
for(int y=0; y<=10; y++)
{
if(y%2==0)/*It separates the ODD and EVEN*/
{
cout<<" "<<a[y];
}
else
{
cout<<"\t"<<a[y]<<endl;
}
}
return 0;
}
什么应该是正确的代码。 从昨天开始我一直在调试这个。
【问题讨论】:
-
你将很快超越你的界限。用
x检查你在做什么。
标签: c++ arrays integer negative-number