?
2012-11-09 18:49:37 UTC
#include
#include
#include
#include
using namespace std;
int main( )
{
char male[1000], female[1000];
int count = 0, malerank = 0, femalerank = 0, num;
char targetname[16];
cout <<"Type name to search\n";
cin >> targetname;
ifstream infile;
infile.open ("babynames2004.txt");
if (infile.fail( ))
{
cout << "babynames2004.txtopening failed.\n";
exit(1);
}
while(! infile.eof( ))
{
infile >> num;
infile >> male[count];
infile >> female[count];
count++;
}
for (int i = 0; i < 1000; i++)
{
{
if(targetname == female[i])
malerank = i+1;
break;
}
{
if(targetname == female[i])
femalerank = i+1;
break;
}
}
if(malerank != 0 && femalerank !=0){
cout << targetname <<" is ranked "<< malerank <<"among boys.\n";
cout << targetname <<" is ranked "<< femalerank <<"among girls.\n";
}
else if(malerank != 0 && femalerank = 0){
cout << targetname <<" is ranked "<< malerank <<"among boys.\n";
cout << targetname <<" is not ranked among to 1000 girl names.\n";
}
else if(malerank = 0 && femalerank != 0){
cout << targetname <<" is ranked "<< femalerank <<"among girls.\n";
cout << targetname <<" is not ranked among to 1000 boy names.\n";
}
return 0;
}