There is a structure: name, age, gender, street, house, apartment. It is necessary to calculate how many men live in each house. How to calculate the men themselves is understandable, but how to make exactly the sample around the house?
struct anket{ string firstname; string lastname; string midlename; string street_name; string house_number; int apartment_number; string gender; int yo; }; int main(){ int n,m=0,w=0; cout<<"Write please n: "; cin>>n; anket im[n]; for(int i = 0;i<n;i++){ cout<<"Write firstname: "; cin>>im[i].firstname; cout<<"Write lastname: "; cin>>im[i].lastname; cout<<"Write midlename: "; cin>>im[i].midlename; cout<<"Write name of street "; cin>>im[i].street_name; cout<<"Write number of house: "; cin>>im[i].house_number; cout<<"Write number of apartment: "; cin>>im[i].apartment_number; cout<<"Write gender(m/w): "; cin>>im[i].gender; cout<<"Write years old(yo): "; cin>>im[i].yo; } for(int i = 0;i<n;i++){ if( im[i].gender == "m"){ m++; } else{ w++; } } cout<<"Mans: "<<m<<endl; cout<<"Womans: "<<w<<endl; }
This is essentially what I did, but I didn’t understand how to check the housework, because I don’t know what house number they will enter.