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.
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 sex;
char gender;
ifstream file;
file.open("example.txt");
cout << "\nEnter m for males or f for females to choose" << endl;
cin >> gender;
cin.get();
if (gender == 'm'){
while (file >> name >> birthyear >> salary>>sex){
cout << name << ' ' << birthyear << ' ' << salary << ' ' << sex << endl;
}
}
cin.get();
return 0;
}