Answer:
The edited program is as follows
// Program to calculate mean and median of numbers
// Program is written in C++
#include<iostream>
//This program uses a bubble sort to arrange up to 300 household sizes in
// descending order and then prints the mean and median household size.
// Input: Interactive.
// Output: Mean and median household size.
using namespace std;
int main(){
// Declare variables.
const int SIZE = 300;
// Number of household sizes
int householdSizes[SIZE];
// Array used to store 300 household sizes
int x;
int limit = SIZE;
int householdSize = 0; int temp; double sum = 0; double mean = 0; int medianIndex = 0;
// Input household size
cout << "Enter household size or 999 to quit: ";
cin >> householdSize;
// Fill an array with household sizes - the maximum households = 300
x = 0;
while(x < limit && householdSize != 999) {
// Place value in array.
householdSizes[x] = householdSize;
// Calculate total of household sizes using the sum variable
sum+ = householdSizes[x];
x++;
// Get ready for next input item.
cout << "Enter household size or 999 to quit: ";
cin >> householdSize;
}
// End of input loop.
// set the limit to x
// calculate the mean household size by dividing the sum by the limit
mean = sum/x;
cout<<"Mean = "<<mean;
// Sort array
for(i=0; i<(SIZE-1); i++)
{
for(j=0; j<(SIZE-i-1); j++)
{
if(householdSizes[j]>householdSizes[j+1])
{
temp= householdSizes[j];
householdSizes[j] = householdSizes[j+1];
householdSizes[j+1] = temp;
}
}
}
// Set medianIndex
int index = (limit-1)/2;
//Print the median found at householdSizes[medianIndex]
cout<<"Median: "<<householdSizes[medianIndex];
return 0;
}
// End of main function