Modify the given program so that the program is able to calculate and display the number of male and
female employees. Use a function name displayGender() to display counter number of gender.
#include<iostream>
using namespace std;
int main()
{
char name[30];
char gender;
for(int counter = 0; counter < 5; counter++)
{
cout<<"Name of the employee: ";
cin>>ws;
cin.getline(name, 30);
cout<<"Gender of the employee (M / F): ";
cin>>gender;
}
return 0;
}
#include<iostream>
using namespace std;
void displayGender(int males,int females);
int main(){
char name[30];
char gender;
int males=0;
int females=0;
for(int counter = 0; counter < 5; counter++){
cout<<"Name of the employee: ";
cin>>ws;
cin.getline(name, 30);
cout<<"Gender of the employee (M / F): ";
cin>>gender;
if(gender=='M'){
males++;
}
if(gender=='F'){
females++;
}
}
displayGender(males,females);
cin>>gender;
return 0;
}
void displayGender(int males,int females){
cout<<"\nNo. males: "<<males<<"\n";
cout<<"No. females: "<<females<<"\n";
}
Comments
Leave a comment