ICU2Desktop
Technical User
Hi, as you can probably see I am a beginner with C++ and I am trying to write a program that reads in 10 whole #’s and outputs the sum of all #’s greater than 0, the sum of all numbers less than 0 ( which are negative #’s and 0 ) and the sum of all the #’s. I have been able to get the results for the sum of all #’s, but unable to produce the first the others. Any help would be greatly appreciated. Here is what I came up with:
#include <iostream>
using namespace std;
int main( )
{
int n1, n2, n3, n4, n5, n6 , n7 , n8, n9 ,n10, sum_one, sum_two, total_sum;
cout << "Enter ten whole numbers randomly positive or negative:\n";
cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8 >> n9 >> n10;
sum_one = (n1>0)+(n2>0)+(n3>0)+(n4>0)+(n5>0)+(n6>0)+(n7>0)+(n8>0)+(n9>0)+(n10>0);
sum_two = n1+n2+n3+n4+n5+n6+n7+n8+n9+n10 <= 0 ;
total_sum = n1+n2+n3+n4+n5+n6+n7+n8+n9+n10 ;
cout << "The first output will be the sum of all\n"
<< "numbers which are greater than zero\n ";
cout << sum_one;
cout << "The second output will be the sum of all\n "
<< "numbers which are less than or equal to zero\n ";
cout << sum_two;
cout << "The third output will be the total sum of all numbers\n ";
cout << total_sum;
return 0;
}
#include <iostream>
using namespace std;
int main( )
{
int n1, n2, n3, n4, n5, n6 , n7 , n8, n9 ,n10, sum_one, sum_two, total_sum;
cout << "Enter ten whole numbers randomly positive or negative:\n";
cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8 >> n9 >> n10;
sum_one = (n1>0)+(n2>0)+(n3>0)+(n4>0)+(n5>0)+(n6>0)+(n7>0)+(n8>0)+(n9>0)+(n10>0);
sum_two = n1+n2+n3+n4+n5+n6+n7+n8+n9+n10 <= 0 ;
total_sum = n1+n2+n3+n4+n5+n6+n7+n8+n9+n10 ;
cout << "The first output will be the sum of all\n"
<< "numbers which are greater than zero\n ";
cout << sum_one;
cout << "The second output will be the sum of all\n "
<< "numbers which are less than or equal to zero\n ";
cout << sum_two;
cout << "The third output will be the total sum of all numbers\n ";
cout << total_sum;
return 0;
}