I need help finishing this #include<iostream> #include<string> #include<conio.h>
ID: 3800702 • Letter: I
Question
I need help finishing this
#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
struct people
{
string name;
float feet;
float inch;
};
int main()
{
int const SIZE = 100;
people p[SIZE];
int groupSize;
double tallest;
double smallest;
int tallindex, smallindex;
int i = 0;
cout << "How large is your group? 100 is the limit: ";
cin >> groupSize;
while (i<groupSize)
{
cout << "Enter the first name of the person " << i + 1 << endl;
cin >> p[i].name;
cout << "Input their height in feet " << endl;
cin >> p[i].feet;
cout << "Input their height in inch " << endl;
cin >> p[i].inch;
i++;
}
tallest = p[i].feet;
smallest = p[i].feet;
for (int i = 0; i < groupSize; i++)
{
if (tallest < p[i].feet)
{
tallest = p[i].feet;
tallindex = i;
}
if (smallest > p[i].feet)
{
smallest = p[i].feet;
smallindex = i;
}
}
cout << " The tallest person is " << p[tallindex].name << " at " << p[i].feet << " feet " << p[i].inch << " inches."<< endl;
cout << " The smallest person is " << p[smallindex].name << " at " << p[i].feet << " feet " << p[i].inch << " inches." << endl;
return 0;
}
Explanation / Answer
#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
struct people
{
string name;
float feet;
float inch;
};
int main()
{
int const SIZE = 100;
people p[SIZE];
int groupSize;
double tallest;
double smallest;
int tallindex, smallindex;
int i = 0;
cout << "How large is your group? 100 is the limit: ";
cin >> groupSize;
while (i<groupSize)
{
cout << "Enter the first name of the person " << i + 1 << endl;
cin >> p[i].name;
cout << "Input their height in feet " << endl;
cin >> p[i].feet;
cout << "Input their height in inch " << endl;
cin >> p[i].inch;
i++;
}
tallest = p[i].feet;
smallest = p[i].feet;
for (int i = 0; i < groupSize; i++)
{
if (tallest < p[i].feet)
{
tallest = p[i].feet;
tallindex = i;
}
if (smallest > p[i].feet)
{
smallest = p[i].feet;
smallindex = i;
}
}
cout << " The tallest person is " << p[tallindex].name << " at " << p[i].feet << " feet " << p[i].inch << " inches."<< endl;
cout << " The smallest person is " << p[smallindex].name << " at " << p[i].feet << " feet " << p[i].inch << " inches." << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.