Project help

need help starting and understanding this project

Write a program that reads in ten whole numbers and that outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative or zero), and the sum of all the numbers, weather positive, negative or zero. The user enters the ten numbers just once and user can enter them in any order. Your program should not ask the user to enter positive numbers and the negative numbers separately.
1. Ask the user to input 10 arbitrary whole numbers.
2. Loop through the numbers.
- a. If the number is positive, add it to the sum of positive numbers.
- b. If the number is negative, add it to the sum of negative numbers.
- c. Add the number to the sum of all numbers.
3. Output the sums separately.
Last edited on
Mrp

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
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs,char* pszArgs[])
{
    int data[10];
    int relayer = 0;
    int total = 0;
    int ntotal = 0;

    cout << "Hi, please input 10 numbers. " << endl;

    for(int relay = 0;relay < 10;relay++)
    {
        cout << "Number " << relay + 1 << ": ";
        cin >> relayer;
        data[relay] = relayer;

        if(data[relay] > 0)
        {
            total += data[relay];
        }
        if(data[relay] < 0)
        {
            ntotal += data[relay];
        }
    }

    cout << "Positive sum: " << total << endl;
    cout << "Negative sum: " << ntotal << endl;

    system("PAUSE");
    return 0;
}
@greenleaf
the OP also requires the overall total
btw it seem a waste of resources to use a container to hold the data when it could be executed as Branflakes outlined in his/her algorithm
?
delete line 8, 19 and change data[relay] in line 21, 23, 25, 27 to relayer and you get the same result, plus saving (>)40 bytes of memory.
Topic archived. No new replies allowed.