In: Computer Science
C++: Design a program that takes the height of 10 people (you may take the heights in inches) and calculates average height. Based on the average height of these 10 people, determine if this group is better suited to be an MLB team, NBA team, or a group of Jockeys (e.g. Kentucky Derby).
The program is to be user friendly, meaning it is to be used by someone who has never programed.
This program is to loop with a “way out.” “Way out” meaning, a way to shut the program down without closing the window. And, when I mean by loop, I mean the program just restarts after analyzing the first 10 people.
Other requirements
-incorporate an array in collecting your data.
-demonstrate the use of if statements
-demonstrate the use of a loop or loops (if necessary)
-round to whole numbers
-output the average height in feet and inches the average
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
char ch;
float heights[10],sum=0.0,avg,average_height;
int i,feet,inches;
do
{
cout<<"Enter the height in inches of a group of 10 students : "<<endl;;
for(i=0;i<10;i++) //Taking input of heights of 10 persons
cin>>heights[i];
for(i=0;i<10;i++)
sum=sum+heights[i];
avg=sum/10;
average_height=avg*0.08333;
feet=(int)average_height; //Average height in feet and inches
inches=ceil(average_height-feet); //ceil function is defined in the library header file math.h
cout<<"The average height of the group of 10 students is : "<<feet<<" feet "<<inches<<" inches"<<endl;
if(avg>=73)
cout<<"The group is best suited to be an MLB team "<<endl;
else if(avg>=70 && avg<73)
cout<<"The group is best suited to be a NBA team "<<endl;
else
cout<<"The group is best suited to be on the team of jockeys"<<endl;
cout<<"Press 'y' to enter another set of heights or '#' to quit : "; //A way out of the program
cin>>ch;
}while(ch!='#');
return 0;
}
The output of the code is :
PLEASE LIKE THE ANSWER IF YOU FIND IT HELPFUL OR YOU CAN COMMENT IF YOU NEED CLARITY / EXPLANATION ON ANY POINT.