This code it's not working, fix it for me please
#include <iostream>
using namespace std;
class People
{
string name;
double height;
public:
void setName(string name)
{
this->name = name;
}
void setHeight(double height)
{
this->height = height;
}
double getHeight()
{
return height;
}
string getName()
{
return name;
}
};
int main()
{
const int size = 100;
string name;
double height;
double tallest;
double smallest;
int groupSize;
int tallindex, smallindex;
cout << "How large is your group? 100 is the
limit: ";
cin >> groupSize;
People people[size];
for (int i = 0; i<groupSize; i++)
{
cout << " Person " << i
+ 1 << " name:";
cin >> name;
cout << " Person " << i
+ 1 << " height:";
cin >> height;
people[i].setName(name);
people[i].setHeight(height);
cout << endl;
}
tallest = people[0].getHeight();
smallest = people[0].getHeight();
for (int i = 0; i<groupSize; i++)
{
if
(tallest<people[i].getHeight())
{
tallest =
people[i].getHeight();
tallindex =
i;
}
if
(smallest>people[i].getHeight())
{
smallest =
people[i].getHeight();
smallindex =
i;
}
}
cout << "\n The tallest person is " <<
people[tallindex].getName() << endl;
cout << "\n The smallest person is " <<
people[smallindex].getName() << endl;
return 0;
}
Check this out, just initialized tallindex and smallindex.
OutPut
Get Answers For Free
Most questions answered within 1 hours.