the "f" for female is not being recognized so it is not outputting what it should and also the count statement is giving out an incorrect format could someone give me some pointers as to what im doing wrong

#include<iostream>
#include<string>
using namespace std;
int main(){
    int femalecount=0,malecount=0,total;
    string race,office,sex;
for(int i=0; i<2; i++)
{
    cout<<"\nwhat is your sex?? answer using f(female) or m(male) ";
    cin>>sex;
    cout<<"\nwhat is your race?? answer using b(black) or w(white) ";
    cin>>race;
    cout<<"\ndo you work in a office?? y(yes) n(no)";
    cin>>office;
    if((sex=="F")||(sex=="m") && race=="w" && office=="y" )
    {
        cout<<"\nyou are allowed to enter the clan ";
        cout<<endl;
}

     else 
    {
        cout<<"\nyou cannot join the clan ";
    }
     if ((sex=="f")||(sex=="m")&&race=="w" && office=="y" ){
        femalecount=femalecount+1;
        malecount=malecount+1;
        total=malecount+femalecount;
    }




}
    cout<<"\nthe num

ber of persons allowed to join the clan are "<<total;

}

The problem seems to be the simplest of all: in the if() statement, you compare sex to "F" (capital F) instead of "f" (lowercase f). This can be solved simply by changing the character being compared, though I would actually recommend a more general solution, by forcing the characters to one case or the other before testing:

int femalecount=0,malecount=0,total;
char race, office, sex;

for(int i=0; i<2; i++)
{
    cout<<"\nwhat is your sex?? answer using f(female) or m(male) ";
    cin>>sex;
    sex = toupper(sex);
    cout<<"\nwhat is your race?? answer using b(black) or w(white) ";
    cin>>race;
    race = toupper(race);
    cout<<"\ndo you work in a office?? y(yes) n(no)";
    cin>>office;
    office = toupper(office);
    if((sex == 'F')||(sex =='M') && race=='W' && office=='Y' )
    {
        cout<<"\nyou are allowed to enter the clan ";
        cout<<endl;
    }

You'll need to #include <cctype> to get the toupper() function.

Edited 2 Years Ago by Schol-R-LEA

This article has been dead for over six months. Start a new discussion instead.