Using I/O Streams

I have a problem with this source code. I would like to put a statement after the statement that executes if(inputName == boyName). I tried to an else after that and all it would do is repeat that statement for 1000 baby names. Instead of saying that boyName isn't ranked only one time. I also tried another if statement saying (inputName != boyName) but it still repeats. I have the same problem with the girlName also. I don't understand if you can i would like some help plz...
Here is my source code along with the list of babies names text document.
You are supposed to read a file and say what name and rank that boy or girl name is associated with. And if there is no match it should also indicate that there is no match. The list of babies names is to big to fit on this page but with replys I'll send the list of babies names.


Source Code:

#include <iostream>
#include <fstream> // Used for allowing input or output for files:
#include <string>
#include <cstdlib> // Used for using the exit command:

using namespace std;

// What this void function is for is explained below
void spaces();

int main()
{
string inputName, boyName, girlName;
int rank;
char response;
ifstream babyName;

do
{
babyName.open("babyNames2004.txt");
if (babyName.fail())
{
cout << "Baby Names could not open up!";
exit(1);
}

cout << "Please enter the name to search for please: ";
cin >> inputName;
spaces();// Statement Spaces

while (babyName >> rank)
{
// Instream reads in a match for a boyName and reads for a match for a girlName:
babyName >> boyName;
babyName >> girlName;

// Says if inputName is their do body command:
if (inputName == boyName)
{
cout << inputName << " is ranked "
<< rank << " in popularity among boys.\n";
}

// Says if inputName is there do body command:
if (inputName == girlName)
{
cout << inputName << " is ranked "
<< rank << " in popularity among girls.\n";
}
}

spaces();// Statement Spaces
babyName.close();
babyName.clear();

cout << "Would you like to enter another name (Y or y) ";
cin >> response;
spaces();// Statement Spaces

}while(response == 'Y' || response == 'y');

return 0;
}

// This void function is used for spaces between my statements:
void spaces()
{
cout << endl << endl;
}
Topic archived. No new replies allowed.