Answer to Question #326222 in C++ for Mano

Question #326222

Input the gender of 10 students in the form of m, M or f, F. Display how many students are male and female. Use for loop and while loop.

1
Expert's answer
2022-04-09T17:54:23-0400
#include <iostream>


using namespace std;


int main(){
	int totalFemale=0;
	int totalMale=0;
	for(int s=0;s<10;s++){
		char gender=' ';
		while(gender!='f' && gender!='F' && gender!='m' && gender!='M'){
			cout<<"Select gender for student "<<(s+1)<<" (f,F - female, m,M - male): ";
			cin>>gender;
		}
		if(gender=='f'|| gender=='F'){
			totalFemale++;	
		}else{
			totalMale++;
		}
	}
	//display result
	cout<<"The number of female students in class: "<<totalFemale<<"\n";
	cout<<"The number of male students in class: "<<totalMale<<"\n\n\n";


	system("pause");
	return 0;
}

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