请指导一下这个程序的错误之处,我思索半天感觉那个指针好像运用有问题,就是不知道问题出在何处,还请大家帮忙看看啊
#include<iostream>using namespace std;
int main()
{
int *p,i,num,positive=0,negative=0;
int p=new int[20];
if (!p)
{
cout<<"number error.\n";
return 1;
}
do{
cin>>num;
}while(num>20||num<1);
for(i=0;i<num;i++)
{
cin>>*(p+i);
if (*(p+i)>0)
positive++;
if (*(p+i)<0)
negative++;
}
delete []p;
cout<<"There are "<<num<<" figures,\n";
cout<<positive<<" of them are positive numbers,\n";
cout<<negative<<" of them are negatives.\n";
return 0;
}
[ 本帖最后由 随着心飞翔 于 2013-3-10 15:25 编辑 ]