C++ 请看看我这个哪里错了

来源:百度知道 编辑:UC知道 时间:2024/05/16 05:31:14
#include<iostream>
using namespace std;
void main()
{
int x;
cout<<"please input ten int numbers"<<endl;
cin>>x;
int i=0,j=0,k=0,a=1;
while(a<=10)
{
++a;
if(x>0)
i++;
else
if(x==0)
k++;
else
j++;

}
cout<<"正整数个数"<<i<<endl<<"0的个数"<<k<<endl<<"负整数个数"<<j<<endl;

}

是输入10个数,统计正整数,负整数,0的个数,可就是看不出哪里有问题

#include<iostream>
using namespace std;
void main()
{
int x;
cout<<"please input ten int numbers"<<endl;
int i=0,j=0,k=0,a=1;
while(a<=10)
{ cin>>x;
++a;
if(x>0)
i++;
else
if(x==0)
k++;
else
j++;

}
cout<<"正整数个数"<<i<<endl<<"0的个数"<<k<<endl<<"负整数个数"<<j<<endl;

}

cout<<"please input ten int numbers"<<endl;
cin>>x;
你这里只输入了一个数啊

把cin>>x;
放到while里面就可以了

程序结构问题.
建议你先画一下流程图.

应把输入放入while循环中
#include<iostream>
using namespace std;
int main()
{
int x;
cout<<"please input ten int numbers"<<endl;
int i=0,j=0,k=0,a=1;
while(a<=10)
{ cin>>x;
++a;
if(x>0)
i++;