In: Computer Science
Design a program that takes the height of 10 people (you need to take the heights and 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 Input should be be inputed Feet, inches and the output should also feet ,inches. This program should also have a loop as to provide the user with a way out of the program.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks
#include<iostream>
using namespace std;
int main(){
//number of people
const int size=10;
//upper limit of average height of a jockey, change this as needed
const int jockey_height=5*12 + 6; //5 ft 6 inches
//upper limit of average height of an MLB player, change this as needed
const int mlb_player_height=6*12 + 2; //6 ft 2 inches
cout<<"Enter heights of "<<size<<" people:"<<endl;
//initializing total height in inches to 0
int heightSum=0, feet, inches;
//looping for size times
for(int i=1;i<=size;i++){
//asking and reading height of current person in ft and inches
cout<<"Enter height of person "<<i<<" (in feet and inches): ";
cin>>feet>>inches;
//converting input to inches and adding to heightSum
heightSum+=feet*12+inches;
}
//finding average height in inches
int heightAvg=heightSum/10;
//converting average height in inches to ft and inches
int avgHeightFeet=heightAvg/12;
int avgHeightInches=heightAvg%12;
//displaying it
cout<<"Average height is "<<avgHeightFeet<<" ft "<<avgHeightInches<<" inches"<<endl;
//now if average height is within the height limit of jockey, printing that they are
//better suited to be Jockeys.
if(heightAvg<=jockey_height){
//<= 5 ft 6 inches
cout<<"This group is better suited to be a group of Jockeys"<<endl;
}
//if average height is within the height limit of MLB players, printing that they are
//better suited to be MLB team.
else if(heightAvg<=mlb_player_height){
//>= 5 ft 6 inches and <= 6 ft 2 inches
cout<<"This group is better suited to be an MLB Team"<<endl;
}
//otherwise, better suited to be an NBA team.
else{
//> 6 ft 2 inches
cout<<"This group is better suited to be an NBA Team"<<endl;
}
return 0;
}
/*OUTPUT*/
Enter heights of 10 people:
Enter height of person 1 (in feet and inches): 5 5
Enter height of person 2 (in feet and inches): 6 3
Enter height of person 3 (in feet and inches): 5 8
Enter height of person 4 (in feet and inches): 6 2
Enter height of person 5 (in feet and inches): 7 1
Enter height of person 6 (in feet and inches): 6 0
Enter height of person 7 (in feet and inches): 5 9
Enter height of person 8 (in feet and inches): 6 4
Enter height of person 9 (in feet and inches): 7 1
Enter height of person 10 (in feet and inches): 6 5
Average height is 6 ft 2 inches
This group is better suited to be an MLB Team