I'm new to C++ and I'm having so much trouble with this problem. I honestly don't know what I'm doing wrong, I've tried everything but I still can't seem to make the program work. This is the problem:
Write a program that reads in ten whole numbers and that outputsthe sum of all the numbers greater than zero, the sum of all thenumbers less than zero (which will be a negative or zero), and thesum of all the numbers, whether positive, negative, or zero. Theuser enters the ten numbers just once each and the user can enterthem in any order. Your program should not ask the user to enterthe positive numbers and the negative numbers separately. Now, modify this program so that it outputs the sum of all positivenumbers, the average of all positive numbers, the sum of allnon-positive numbers, the average of all non-positive numbers, thesum of all positive and non-positive numbers, and the average ofall numbers entered.
This is what I have:
#include <iostream>
using namespace std;
int main ()
{
// Set four counters to zero that is,
// sum_greater_than_zero, num_greater_than_zero, sum_less_than_zero, num_less_than_zero.
int numb =0 ;
int sum_greater_than_zero = 0, num_greater_than_zero = 0, sum_less_than_zero = 0, num_less_than_zero = 0;
int positiveSum= 0, nonpositiveSum=0;
int positiveAverage=0, nonpositiveAverage=0;
int counter= 10;
// Use a for loop done 10 times:
for (int i = 0; i < 10; i++)
{
cout << "Please enter any number that you'd like. \n ";
cin >> numb;
}
// Use if else statement:
if (numb > 0)
{
sum_greater_than_zero += num_greater_than_zero ;
}
else if (numb < 0 )
{
sum_less_than_zero += num_less_than_zero;
}
counter ++;
// Average of numbers:
//(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) =(1+2+3+4+5+6+7+8+9+10)/10=5.5
//
positiveSum = (sum_greater_than_zero + sum_less_than_zero);
nonpositiveSum = (num_greater_than_zero + num_less_than_zero);
positiveAverage = (sum_greater_than_zero/num_greater_than_zero);
nonpositiveAverage = (sum_less_than_zero/num_less_than_zero);
{
cout << " The sum of positive numbers: " << positiveSum << endl;
cout << " The average of positive numbers: " << positiveAverage << endl ;
cout << " The sum of nonpositive numbers: " << nonpositiveSum << endl ;
cout << " The average of nonpositive numbers: " << nonpositiveAverage << endl ;
}
cout << endl;
return 0;
}
All help is truly appreciated!