#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
usingnamespace std;
int main()
{
char boys[1000][20], girls[1000][20], name[20], found;
int count = 0;
int rankofboys, rankofgirls, num;
cout << "Enter the first name of the baby that you want to find\n";
cin >> name;
ifstream in;
in.open("babynames2004.txt");
if(in.fail())
{
cout << "Input file opening failed.\n";
exit(1);
}
while(count < 1000 && in >>boys[count] >> girls[count])
{
count++;
}
for(int i = 0; i < 1000; i++)
{
if(strcmp(name, boys[i])==0)
{
found = true;
rankofboys= i+1;
}
if(strcmp(name, girls[i]) ==0)
{
found = true;
rankofgirls= i+1;
}
if(rankofboys !=0 && rankofgirls !=0)
{
cout << name << " is " << rankofboys << "on the rankings for boys.\n";
cout << name << " is " << rankofgirls << "on the rankings for girls.\n";
}
elseif (rankofboys !=0 && rankofgirls == 0)
{
cout << name << " is " << rankofboys << "on the rankings for boys.\n";
cout << name << " is not ranked in the top 1000 girl names.\n";
}
elseif (rankofboys == 0 && rankofgirls !=0)
{
cout << name << " is " << rankofgirls << "on the ranking for girls.\n";
cout << name << " is not ranked in the top 1000 boy names.\n";
}
}
}
You'd better post _what_ exactly you tried. You see, I'm not good in telepathy.
And by the way, what exactly is your task, and format of input file? You looks like trying to do reading statistics and printing results in the same loop - I think it is not what are you wanted to do.