The program is suppose to
1. Pull 5 offensive players into a file. Pull 3 defensive players into a file.
2. Sort both files by LAST name.
The error says
error C3861: 'bubblesort2': identifier not found.

//Laura Patrick
//EGR 126-11
//March 20, 2007
//Ex 11.5 #6
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<string>
#include<fstream>
#include<vector>
usingnamespace std;
struct players
{
string fname;
string lname;
int atbats;
int runs;
int hits;
int doubles;
int triples;
int hrs;
int rbi;
int sos;
double avg;
};
int main()
{
 
//void bubblesort2(players team[]);
string ifile="top100off.txt", ofile="top60def.txt", name;
players team[45];
int i, c;
 
ifstream inFile; //this is the incoming file block
inFile.open(ifile.c_str());
if (inFile.fail()) 
{
cout << "The file was not opened successfully opened. Make sure the file is real." << endl;
exit(1);
}
inFile >> team[0].fname >> team[0].lname >> team[0].atbats >> team[0].runs
>> team[0].hits >> team[0].doubles >> team[0].triples >> team[0].hrs 
>> team[0].rbi >> team[0].sos >> team[0].avg;
for(i=1; i<45; i++)
{
inFile >> team[i].fname >> team[i].lname >> team[i].atbats >> team[i].runs
>> team[i].hits >> team[i].doubles >> team[i].triples >> team[i].hrs 
>> team[i].rbi >> team[i].sos >> team[i].avg;
cout << team[i].fname << " " << team[i].lname << " " << team[i].atbats << " " << team[i].runs
<< " " << team[i].hits << " " << team[i].doubles << " " << team[i].triples << " " << team[i].hrs 
<< " " << team[i].rbi << " " << team[i].sos << " " << team[i].avg << "\n"; 
}
ofstream outFile; //Create new file block
outFile.open(ofile.c_str());
if (outFile.fail())
{
cout << "Resistance is Futile. You will be assimilated." << endl;
}
bubblesort2(team); <<THERE IS THE ERROR ACCORDING TO C++, BUT I CANT FIGURE IT OUT
 
//Find player to add to list
for (c=1; c<=5; c++)
{
cout << "Enter a last name from the offensive player list. " << endl;
getline(cin, name);
if (islower(name[0]))
{
name[0]=toupper(name[0]);
}
for (i=0; i<45; i++)
{
if (team[i].lname == name)
{
outFile << team[i].fname << " " << team[i].lname << " " << team[i].atbats << " " << team[i].runs
<< " " << team[i].hits << " " << team[i].doubles << " " << team[i].triples << " " << team[i].hrs 
<< " " << team[i].rbi << " " << team[i].sos << " " << team[i].avg << endl;
}
 
}
}
for(i=0; i<45; i++)
{
outFile << team[i].fname << " " << team[i].lname << " " << team[i].atbats << " " << team[i].runs
<< " " << team[i].hits << " " << team[i].doubles << " " << team[i].triples << " " << team[i].hrs 
<< " " << team[i].rbi << " " << team[i].sos << " " << team[i].avg << endl;
}
outFile.close();
 
 
cout << "You have been assimilated.";
cin.ignore();
return 42;
}
void bubbleSort2(players team[]) 
{
bool doMore;
do {
doMore = false; // assume this is last pass over array
for (int i=0; i<45; i++) 
{
if (team[i].lname > team[i+1].lname) 
{
// exchange elements
players temp = team[i];
team[i] = team[i+1]; 
team[i+1] = temp;
doMore = true; // after exchange, must look again
}
}
} while (doMore);
}

Or just use code tags, it's all anyone really needs.

Edited 4 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.