# Beginner to C++ – How to sum up only positive or only negative integers the user inputs and how to calculate the avg Total Noob here, I am having a hard time with an assignment. I am taking a beginner course in C++ and have to figure out how to calculate the sum of negative integers and their avg. Sum of positive integers and the avg. And the sum of all numbers and the avg. I have gotten the last part already but how do I calculate the sum of negative integers and avg, and positive integers and avg using a while loop?

``````I provided my code below.

#include <iostream>
using namespace std;
#include <iomanip>

int main(int argc, const char * argv()) {

int x;
double avg = 0.0;
int count = 0;
int sum = 0;

cout << ("Welcome to the greatest calculator!n");
cout << ("Please enter 10 integers seperated by spaces n");

do {
std::cin >> x;
sum = sum + x;
count = count + 1;
}
while (count < 10);

// calculate average

avg = sum/10.0;

// output average
cout << fixed;
cout << "For all 10 numbers the sum is " << sum << "." "The average is " << setprecision (2) << sum/10.0 <<".n";
return 0;

}

The output should look something like this.

Please enter 10 integers separated by spaces:
1 -1 45 17 28 -2 0 9 -14 11

Upon our intelligent calculations, here is the result:
+ There are 7 positive numbers, sum = 111.00 and average = 15.86
+ There are 3 negative numbers, sum = -17.00 and average = -5.67
+ For all 10 numbers, sum = 94.00 and average = 9.40 */
`````` Posted on Categories Articles