# C ++ programming

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

1. ### 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

2. ### 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