Writing Program w/ Visual studio: C++ **NEED HELP**

Discussion in 'School Work Help' started by aznlitomik3, Sep 22, 2010.

  1. aznlitomik3

    aznlitomik3 Active Member

    30
    234
    0
    The problem I'm working with is

    *Write a program that reads in ten whole numbers from the user. The program will
    calculate and output the following statistics about the ten numbers:
    ● The sum of all of the positive numbers.
    ● The sum of all of the non-positive numbers.
    ● The sum of all ten numbers.
    ● The average of all of the positive numbers.
    ● The average of all of the non-positive numbers.
    ● The average of all ten numbers.
    Note that your program must accept the ten numbers in any order, and can not ask the
    user to enter the positive and non-positive numbers separately.

    *******************************************************************

    What I have so far:

    #include <iostream>
    using namespace std;

    int main()
    {
    int numbers[10];
    int pos=0, neg=0, total=0;
    double total_sum, pos_avg=0, neg_avg=0, total_avg=0;

    for (int i=0; i<10; i++)
    {
    cout << "Enter a positive or negative number " << i+1 << ", then press ENTER: ", i;
    cin >> numbers;

    if (numbers > 0)

    pos += numbers;

    else

    neg += numbers;

    }

    cout << "Sum of all positive numbers: " << pos << endl;
    cout << "Sum of all negative numbers: " << neg << endl;

    total_sum = pos + neg;
    cout << "Sum of all numbers: " << total_sum << endl;

    cout << "Average of all positive numbers: " << pos_avg << endl;
    cout << "Average of all negative numbers: " << neg_avg << endl;

    total_avg = total_sum / 10;
    cout << "Average of all numbers: " << total_avg << endl;

    return 0;
    }


    **************************************************************
    Now I'm only missing the average part where i need to find
    How would i add in the average part to the program i already have

    Thank You!!
     
    #1 aznlitomik3, Sep 22, 2010
    Last edited: Sep 22, 2010
  2. mizuKAZE

    mizuKAZE Well-Known Member

    52
    31
    0
    Give you some hints
    You already have the sum of the positive numbers and the negative numbers.
    To get the average of the positive numbers you have to know:
    - the sum of the positive numbers (which you already have)
    - the numbers of positive numbers

    So you only need a variable which count the total of the positive numbers and negative numbers in the IF-LOOP

    Then at the print out:
    you divide "pos" by the "count_the_total_positive_numbers_variable_you_put_in_the_loop"