I'm sorry, I didn't realize I couldn't upload the exe file - but I have it ready to email.

I'm having a big problem understanding how to complete this assignment and would really appreciate someone's help in getting me started.

Basically, we are taking baby names from a file and opening the file up in our program. we are using arrays (I believe a 2 dimensional array) and taking it from a file named babynames2004.txt and putting that data into the array.

this program is supposed to output to the screen:
"Enter the first name that you would like to find the
popularity of from baby names in 2004.
Be sure to capitalize the first letter of the name."

if you enter Melissa, for example, it will output:

"Melissa is not ranked among the top 1000 boy names.
Melissa is ranked 100 in popularity among girls
Press any key to continue..."

I have attached the text file fo anyone willing to help me continue the project.

I have to load the boy names and the girl names from the file into separate arrays and search for the target name from the arrays, not directly from the file.

here is what I have so far, someone pleeeease help me :)

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;





int main
{
    ifstream in_put;
    char enter_name
    
    in_put.open("babynames2004.txt");
    if (in_put.fail())
    {
       cout << "Input file opening failed.\n";
       exit(1)
    }
    
    cout << "Enter the first name that you would like to find the\n;"
         << "popularity of from baby names in 2004.\n;"
         << "Be sure to capitalize the first letter of the name.\n"
    cin >> enter_name;
    
    int index = 0, count = 0;
    char boys_name[1000][10], girls_name[1000][10];
    char data;
    
    while (in_put.get(data))
    {     
          boys_name[index][count] = data;
          girls_name[index][count] = data;
          
          for (count += 1; count < 10; count ++)
          {
              char boys_name[index][count] = input.get(data);
              if (data == ' ')
                 char girls_name [index][count] = in_put.get(data);
                 
    }
    
    
    
    
    
    
    system("Pause");
    
    return 0;
    
}

>>I'm sorry, I didn't realize I couldn't upload the exe file - but I have it ready to email.
That's ok We don't want you uploading exe files because (1) they can contain viruses and worms and (2) we can compile the code ourselves on our local computer to test it out.

line 13: you should declare that as std::string not char. What you declared is just one single character and I doubt very seriously that anyone would name their baby a single character.

line 29: like line 13 all you declared was a single character. Why read the file one character at a time when you could read it one word or line at a time.

I see that each line of that text file contains 3 words: a number indicating rank and two names. That means what you need to do is to create an array of structures that contain those three items.

struct line
{
     int rank;
     std::string name1;
     std::string name2;
};

now you can create an array of the above structures struct line names[1000]; Now to read those structures into the array

std::string name1, name2;
int rank;
int count = 0;
while(count < 1000 &&  in_put >> rank >> name1 >> name2)
{
    names[count].rank = rank;
    names[count].name1 = name1;
    names[count].name2 = name2;
    ++ count;
}

thank you very much for your help.

so should I delete what I've written and replace it with what you've typed? I'm not sure what to take out and what to leave in.

nvm I commented out what I was doing and fixed something, and it compiled :)

now I'm trying to get it to display some results, and it isn't working -

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;





int main()
{
    ifstream in_put;
    std::string enter_name;
    char data;
    
    in_put.open("babynames2004.txt");
    if (in_put.fail())
    {
       cout << "Input file opening failed.\n";
       exit(1);
    }
    
    cout << "Enter the first name that you would like to find the\n"
         << "popularity of from baby names in 2004.\n"
         << "Be sure to capitalize the first letter of the name.\n";
    cin >> enter_name
    


struct line
{
     int rank;
     std::string name1;
     std::string name2;
};

struct line names[1000];

std::string name1, name2;
int rank;
int index = 0, count = 0;
while(count < 1000 &&  in_put >> rank >> name1 >> name2)
{
    names[count].rank = rank;
    names[count].name1 = name1;
    names[count].name2 = name2;
    ++ count;
}

if (in_put = name1)
	cout << in_put << " is ranked " << rank <<  " in popularity among boys.\n";
else 
	cout << in_put << " is not ranked among the top 1000 boy names.\n";

if (in_put = name2)
	cout << in_put << " is ranked << rank << " in popularity among girls.\n";
else 
	cout << in_put << " is not ranked among the top 1000 girl names.\n";
    
    
    
    
    
    
    system("Pause");
    
    return 0;
    
}

lines 51 and 52: you can't use an ifstream (in_input) like that.

How do you distinguish boy names from girl names? Or is one colums boys and the other girls? After reading the file your program needs to scan through the list and count the number of times each name appears.

[edit]I went ahead and wrote the program (I'm not going to post it though). I found out that text file does not contain any duplicate names, unless of course my program is wrong. So I don't know how you can find the most popular girs and boys names [/edit]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.