Answer to Question #208895 in C++ for syahidah

Question #208895

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;

}


1
Expert's answer
2021-06-20T08:11:49-0400
#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";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS