Answer:
For the mean, do the following:
mean = sum/limit;
cout<<"Mean: "<<mean;
For the median do the following:
for(int i = 0; i<limit; i++) {
for(int j = i+1; j<limit; j++){
if(householdSizes[j] < householdSizes[i]){
temp = householdSizes[i];
householdSizes[i] = householdSizes[j];
householdSizes[j] = temp; } } }
median= (householdSizes[(limit-1)/2]+householdSizes[1+(limit-1)/2])/2.0;
if((limit - 1)%2==0){
median = householdSizes[limit/2];
}
cout<<endl<<"Median: "<<median;
Explanation:
The bubble sort algorithm in your program is not well implemented;
So, I replaced the one in your program with another.
Also, some variable declarations were removed (as they were no longer needed) --- See attachment for complete program
Calculate mean
mean = sum/limit;
Print mean
cout<<"Mean: "<<mean;
Iterate through each element
for(int i = 0; i<limit; i++) {
Iterate through every other elements forward
for(int j = i+1; j<limit; j++){
Compare both elements
if(householdSizes[j] < householdSizes[i]){
Reposition the elements if not properly sorted
temp = householdSizes[i];
householdSizes[i] = householdSizes[j];
householdSizes[j] = temp; } } }
Calculate the median for even elements
median= (householdSizes[(limit-1)/2]+householdSizes[1+(limit-1)/2])/2.0;
Calculate the median for odd elements
if((limit - 1)%2==0){
median = householdSizes[limit/2];
}
Print median
cout<<endl<<"Median: "<<median;