1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include <iostream>
using namespace std;
int main()
{
int num_a, num_b, num_c, num_d, num_e, num_f, num_g, num_h,
num_i, num_j, num_k, sum_pos(0), sum_neg(0), sum;
cout << "This program sums all the positive numbers,\n";
cout << "all the negative numbers, and then sums the\n";
cout << "positive and negative numbers together.\n";
cout << "Enter ten whole numbers, positive or negative,\n";
cout << "then press the return key after each number is\n";
cout << "entered.\n";
cin >> num_n;
if (num_a > 0)
sum_pos+=num_a;
else
sum_neg+=num_a;
if (num_b > 0)
sum_pos+=num_b;
else
sum_neg+=num_b;
if (num_c > 0)
sum_pos+=num_c;
else
sum_neg+=num_c;
if (num_d >0)
sum_pos+=num_d;
else
sum_neg+=num_d;
if (num_e > 0)
sum_pos+=num_e;
else
sum_neg+=num_e;
if (num_f > 0)
sum_pos+=num_f;
else
sum_neg+=num_f;
if (num_g > 0)
sum_pos+=num_g;
else
sum_neg+=num_g;
if (num_h > 0)
sum_pos+=num_h;
else
sum_neg+=num_h;
if (num_i > 0)
sum_pos+=num_i;
else
sum_neg+=num_i;
if (num_j > 0)
sum_pos+=num_j;
else
sum_neg+=num_j;
sum = sum_pos + sum_neg;
cout << "Your sum for positive is\n";
cout << sum_pos << endl;
cout << "Your sum for negative is\n";
cout << sum_neg << endl;
cout << "Your total sum of both positive and negative is\n";
cout << sum << endl;
return 0;
}
|