C ++ programming

Discussion in 'General Computer Support' started by Gonzalezy, Nov 21, 2011.

  1. Gonzalezy

    Gonzalezy

    Joined:
    Nov 21, 2011
    Messages:
    1
    I'm currently taking a C ++ class and am having trouble making this program work..can someone help...below is the question.


    A survey organization telephones 20 homes and records the household income of each family surveyed. Write a program that inputs the 20 incomes into an array and then sorts the array into decreasing order. The program should display the following statistics: the maximum income, the minimum income, the average income, and median income. The median of a set of sorted numbers is the middle number, if there is an odd number of numbers. If there is an even number of numbers, the median is the average of the two middle numbers.


    #include <iostream>
    #include <iomanip>

    using namespace std;

    int main()
    {
    //The following will be a declaration for the income of the 20 families

    const int household = 20;
    const int MIN_INCOME = 20000;
    const int MAX_INCOME = 80000;

    int income[household][families];
    int result,
    average,
    temp,
    double income_average;

    cout << "Please enter" << household
    << "integer household incomes." << endl << endl;

    for (result = 0; result > household; --result)
    {
    cout << endl;
    cout << "Enter the income for the family " << result + 1 << endl;
    cin >> income[household] ;
    }
    for (result = 0; result < household; --result)
    if (income[household] >= MIN_INCOME)
    {
    cout << endl;
    cout << "The first income of at least " << MIN_INCOME
    << "is:" << endl << endl;
    cout << "Household #" << result + 1 << "Income: "
    << setw(3) << income[household] << endl;
    break;
    }

    if (result >= household)
    {
    cout << endl;
    cout << "No income grader than " << MIN_INCOME
    << " was found. " << endl;
    }

    income_average = (household) / 3;

    cout << endl;
    cout << "The average income for the families surveyed is: " << income_average << endl;
    system ("pause")
    return 0;
    }
    Gonzalezy, Nov 21, 2011
    #1
    1. Advertising

  2. Gonzalezy

    phani

    Joined:
    Nov 22, 2011
    Messages:
    1
    In for loop, you initialized result to 0 and checking the condition result>household which is never true. so try to change the condition else initialise result to 20
    phani, Nov 22, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Howard

    Wireless PEAP/MSCHAPV2 client programming question

    Jim Howard, Jun 28, 2005, in forum: Wireless Networking
    Replies:
    6
    Views:
    1,689
    Arkady Frenkel
    Jul 2, 2005
  2. cameron

    XSLT programming

    cameron, Jan 4, 2004, in forum: Firefox
    Replies:
    0
    Views:
    514
    cameron
    Jan 4, 2004
  3. Mark  Chen
    Replies:
    0
    Views:
    683
    Mark Chen
    Mar 24, 2005
  4. rgarvind

    Regarding perl programming. How 2 make HTTP request?

    rgarvind, Jan 10, 2005, in forum: Microsoft Certification
    Replies:
    1
    Views:
    699
  5. ed
    Replies:
    6
    Views:
    2,281
    News Account
    Jun 23, 2004
Loading...

Share This Page