Girl Scout troop 815 has 25 members. Write a program in which the troop leader c
ID: 674315 • Letter: G
Question
Girl Scout troop 815 has 25 members. Write a program in which the troop leader can enter the number of boxes of cookies sold by each scout, and output the total number of boxes sold and the mean and median value. Girl Scout troop 815 has 25 members. Write a program in which the troop leader can enter the number of boxes of cookies sold by each scout, and output the total number of boxes sold and the mean and median value. Girl Scout troop 815 has 25 members. Write a program in which the troop leader can enter the number of boxes of cookies sold by each scout, and output the total number of boxes sold and the mean and median value.Explanation / Answer
Below is the required code :-
#include <iostream>
using namespace std;
float median(int n, int x[]) {
float temp;
int i, j;
for(i=0; i<n-1; i++) {
for(j=i+1; j<n; j++) {
if(x[j] < x[i]) {
// swap elements
temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
if(n%2==0) {
return((x[n/2] + x[n/2 - 1]) / 2.0);
} else {
return x[n/2];
}
}
int main()
{
int noOfBoxes[25];
int i, sum=0;
float mn, mdn;
for(i=0; i<25; i++)
{
cout << "Enter no of box for scout " << i+1 << " ";
cin >> noOfBoxes[i];
}
for(i=0; i<25; i++) sum+=noOfBoxes[i];
mn = sum/25;
mdn = median(25, noOfBoxes);
cout << " Total no of boxes sold : " << sum;
cout << " Mean : " << mn;
cout << " Median : " << mdn;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.