QUESTION 1
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(char *g){
int males = 0;
for(int c = 0; c < 5; c++) {
if(g[c]=='M'){
males++;
}
}
cout<<"Male: "<<males<<endl;
cout<<"Female:"<< 5 - males<<endl;
}
int main() {
char name[30];
char gender;
// Array to store values of gender entered by user
char all_gender[5];
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;
// Assign input gender value to array
all_gender[counter] = gender;
}
displayGender(all_gender);
return 0;
}
Comments
Leave a comment