Answer to Question #30198 in C++ for Tayyab Raza

Question #30198
Input the gender of 10 students and display how many students are male or female??
1
Expert's answer
2013-05-14T11:17:35-0400
#include <iostream>
using namespace std;

const int STUDENTS_COUNT = 3;
const char* MALE = "male";
const char* FEMALE = "female";

int main()
{
char buffer[20] = {};//buffer for user input
int maleCount = 0 ,
femaleCount = 0;

for(int i=0;i<STUDENTS_COUNT;i++)
{
cout<<"Input gender(male ro female) of student # "<<i+1<<" : ";
cin>>buffer;
if(!stricmp(buffer,MALE))
maleCount++;
else if(!stricmp(buffer,FEMALE))
femaleCount++;
}

cout<<"\nMale students : "<<maleCount<<endl;
cout<<"Female students : "<<femaleCount<<endl;

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
APPROVED BY CLIENTS