Need Help

My question is how would i write my code to allow only m=male to appear only not the f=female. I'm sorry if thats too much to ask i just started learning so im sorry if i am a beginner. Here is the text file that says all the details:
Josheph 1985 $10000 m
Nina 1998 $5000 f
Mark 1990 $20000 m
Katlyn 1989 $50000 f
Joe 1967 $90000 m
Nick 1970 $70000 m
Rose 1980 $10000 f
Alice 1965 $200000 f
Emmett 1978 $50000 m
Charlie 1969 $54000 m
Jessica 1992 $199999 f

And this is my code so far, im trying to change and add stuff to debug the code but it does not print only male details prints out everything. I looked all over google to find out how to do it but i cant seem to find one.

Code:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
string name;
string birthyear;
string salary;
string gender;
char male = 'm';
char female ='f';

ifstream file;
file.open("example.txt");

cout << "\nEnter m for males or f for females to choose" << endl;
cin >> gender;
while (file >> name >> birthyear >> salary >> gender){
cout << name << ' ' << birthyear << ' ' << salary << ' ' << "m"<< endl;
cin.get();
if (gender == "m"){
cout << name << ' ' << birthyear << ' ' << salary<< endl;
cin.get();
}
else if (gender == "f"){
cout << name << ' ' << birthyear << ' ' << salary << ' ' << female << endl;
cin.get();
}
}
cin.get();
return 0;
}
Please use code tags when posting code. Highlight the code, then press the <> button in the Format menu to the right.

To print only the "m" records, just remove the else clause in your main program.
1
2
cin >> gender;
while (file >> name >> birthyear >> salary >> gender)


You're using the same variable gender to get input from the user and the file. The user might put in "m", but then it gets overwritten with whatever is in the current record read from the file.
Topic archived. No new replies allowed.