A
A
Archpriest Metapop2020-10-26 05:01:14
C++ / C#
Archpriest Metapop, 2020-10-26 05:01:14

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;
}

Probably I messed up something with memory.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-10-26
@caramel14

The man array is not declared.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question