Answer the question
In order to leave comments, you need to log in
I can't deal with structures in C++. How to solve the problem?
According to the condition, you need to create a structure consisting of the name, gender and height of a person, and then calculate the average height of the girls.
But it's not entirely clear to me how to organize the memory and where the data will be stored?
+ I do not quite understand how to enable the addition of a new element.
const int n = 50;
struct info {
string Name[n];
int H;
char Sex[n];
};
info WriteStruct(info) {
info man;
cin.get();
cout << "Введите Имя: ";
cin << man.Name();
cout << "Введите Рост: ";
cin << man.Н;
cout << "Введите пол: [M]/[F]";
cin << man.Sex();
return man;
}
Answer the question
In order to leave comments, you need to log in
stringName[n];
struct info {
std::string Name;
int H;
char Sex;
};
std::vector<info> people;
info man = WriteStruct(info);
people.push_back(man);
for (int i = 0; i < people.size(); i++) {
info man = people[i];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question