A program that asks 10 positive integers and classify them as odd or even positive integer inputs. The algorithm has to trap negative integer inputs. The output will be displayed in two columns. ODD and EVEN.
So how to catch negatives and notify invalid output? or re-prompt until a positive number is caught?
here's my program code...
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;
}
What should be the right code for this. I've been debugging this since yesterday.
x.