Velocity Reviews > C ++ programming

# C ++ programming

Gonzalezy
Junior Member
Join Date: Nov 2011
Posts: 1

 11-21-2011
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;
}

phani
Junior Member
Join Date: Nov 2011
Posts: 2

 11-22-2011
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

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Joe Mayo C Programming 168 10-22-2007 01:00 AM Casey Hawthorne Python 4 08-04-2006 05:23 AM Jim Howard Wireless Networking 6 07-02-2005 11:53 AM Matt Java 35 07-22-2004 08:10 AM cameron Firefox 0 01-04-2004 10:51 PM