Adding the sum of numbers using a loop statement

Posted by Deonna on Stack Overflow See other posts from Stack Overflow or by Deonna
Published on 2010-03-28T18:03:05Z Indexed on 2010/03/28 19:43 UTC
Read the original article Hit count: 240

Filed under:
|
|
|
|

I need serious help dividing the positive numbers and the negative numbers.

I am to accumulate the total of the negative values and separately accumulate the total of the positive values. After the loop, you are then to display the sum of the negative values and the sum of the positive values.

The data is suppose to look like this:

-2.3 -1.9 -1.5 -1.1 -0.7 -0.3 0.1 0.5 0.9 1.3 1.7 2.1 2.5 2.9
Sum of negative values: -7.8 Sum of positive
values: 12

So far I have this:

int main () {

    int num, num2, num3, num4, num5, sum, count, sum1;
    int tempVariable = 0;
    int numCount = 100;
    int newlineCount = 0, newlineCount1 = 0;
    float numCount1 = -2.3;

    while (numCount <= 150)
    {
        cout << numCount << " ";

        numCount += 2;
        newlineCount ++; 
        if(newlineCount == 6)
        {
            cout<< " " << endl;
            newlineCount = 0;
        }
    }
    **cout << "" << endl;
    while (numCount1 <=2.9 ) 
    {
        cout << numCount1 << " ";
        numCount1 += 0.4;
        newlineCount1 ++;     
    } while (  newlineCount1  <= 0 && newlineCount >= -2.3 );

    cout << "The sum is " << newlineCount1 << endl;**

    return 0;   
}

© Stack Overflow or respective owner

Related posts about coding-style

Related posts about loop