返回指针类型的一个小问题..需要请教..

来源:百度知道 编辑:UC知道 时间:2024/07/01 08:00:01
#include<iostream.h>
int *count(int *n );
int *a,*b;
void main()
{
int x;
cout<<"Input nmubers,the 0 is end:\n";
cin>>x;
while(x)
{
*count(&x)++;
cin>>x;
}
cout<<"the number of right: "<<a<<endl;
cout<<"the number of negative: "<<b<<endl;
}
int *count(int *n)
{
if(n>0)
return a;
else
return b;
}

*count(&x)++;这个句子有点问题.不知道怎样改..高手求助了..

不太清楚你这个程序的意,下面是可运行版本.
#include<iostream>
#include <conio.h>
using namespace std;
int *count(int *n );
int ao =0;
int bo =0;
int *a = &ao ,*b = &bo;
int main()
{
int x;
cout<<"Input nmubers,the 0 is end:\n";
cin>>x;
while(x)
{
(*count(&x))++;
cin>>x;
}
cout<<"the number of right: "<<*a<<endl;
cout<<"the number of negative: "<<*b<<endl;
getch();
return 0;
}
int *count(int *n)
{
if(*n>0)
return a;
else
return b;
}

程序至少有十处以上是基本语法错误