Answer the question
In order to leave comments, you need to log in
The program with structures does not work. What am I doing wrong?
As planned, the program should read the data into structures, and then find the average height (H) among women (F), but it does not work.
#include <iostream>
#include <iomanip>
using namespace std;
struct info {
std::string Name;
int H;
char Sex;
};
int a,srz,srz1;
int main() {
cout << "Введите кол-во учеников: \n";
cin >> a;
srz = 0;
srz1 = 0;
for(int i = 0; i < a; i++) {
info man[i];
std::cin.get();
std::cout << "Введите Имя ученика "<<i+1<<" :\n";
std::cin >> man[i].Name ;
std::cout << "Введите Рост ученика "<<i+1<<" :\n";
std::cin >> man[i].H;
std::cout << "Введите пол [M]/[F] ученика "<<i+1<<" :\n";
std::cin >> man[i].Sex;
}
for (int i = 0; i < a; i++) {
info man[i];
if (man[i].Sex == 'F') {
srz = man[i].H +srz;
srz1 = srz1++;
}
}
srz = srz/srz1;
cout <<"Средний рост девушек:" << srz;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question