I'm trying to break this problem into function, but my problem is that I always get different sum, positive and negative count when I print out the result.
Can someone give me a hint?
Write a program that reads ten integer numbers and outputs the sum of all the positive numbers among them. The program should ignore all numbers which are less than or equal to 0. The program should also display count of positive numbers and count of negative numbers or zero.
#include <iostream>
using namespace std;
void input(int number, int positiveCount, int negativeCount, int sum);
void output(int positiveCount, int negativeCount, int sum);
int main()
{
int number, positiveCount, negativeCount, sum;
input(number, positiveCount, negativeCount, sum);
output(positiveCount, negativeCount, sum);
return 0;
}
void input(int number, int positiveCount, int negativeCount, int sum)
{
cout << "Enter 10 integers: " << endl;
for (int i = 0; i < 10; i++)
{
cin >> number;
if (number > 0)
{
positiveCount++;
sum = sum + number;
}
else
{
negativeCount++;
}
}
}
void output(int positiveCount, int negativeCount, int sum)
{
cout << sum << endl;
cout << positiveCount << endl;
cout << negativeCount << endl;
}