#include <iostream>
usingnamespace std;
void countFreq(int);
int sumPos(int);
int sumNeg(int);
int main ()
{
int a, totp, totn;
cout << "Enter 10 integers: " << endl;
for (int i=0;i<10;i++)
{
cin >> a;
}
totp = sumPos(a);
totn = sumNeg(a);
countFreq(a) ;
cout <<endl << "The sum of positive number is: " << totp<< endl;
cout << "The sum of positive number is: " << totn;
return 0;
}
void countFreq(int c)
{
int pn=0, nn=0, z=0;
if (c > 0)
pn += 1;
elseif (c<0)
nn += 1;
else
z += 1;
cout << "There are " << pn << " positive numbers, " << nn << " negative numbers and " << z << " zeroes.";
}
int sumPos(int a)
{
int tpn;
tpn += a;
return tpn;
}
int sumNeg(int b)
{
int tnn;
tnn += b;
return tnn;
}
Your code have a very basic issue. The loop which is taking input in "a" is overwriting the value of "a" after every input. So at the end of this loop you have only one value of "a".
1 2 3 4
for (int i=0;i<10;i++)
{
cin >> a;
}
what you should do is create array instead of single variable