Look at the bold lines, you were comparing the wrong data, and overwriting what the user inputted.
Code:
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
int main()
{
// Declare variables
char band[80];
char cd_name[80];
char lookfor[80]; // user input will be stored here
int found;
ifstream infile;
found = 0;
cout << "Sheila Blakely\n";
cout << "Final 2002\n\n";
cout << "Music Library\n";
//Input from the user
cout << "Enter a singer or band name: ";
cin.get(lookfor,80);
cin.ignore(80, '\n');
cout << '\n';
infile.open ("LIBRARY.TXT", ios::in); // open the library file
if(infile)
{
do
{
infile.get(band, 80); // i changed the declaration of band and cd_name to 80 chars, so you can read up to 80 chars
infile.ignore(80, '\n');
infile.get(cd_name, 80); // get the CD name from the file
infile.ignore (80, '\n');
if ((strcmp (band, lookfor)) == 0 ) //you were comparing the band to the cdname, so jimmy eat world, the first entry in the text file would always be found
{
found = 1;
break;
}
}
while (found != 1 && !infile.eof());
}
else
{
"An error occured while opening the file.\n";
}
infile.close(); // close the input file
if (found == 1)
{
cout << "The book title that you requested is in our inventory.\n\n";
cout << "***CD Information*** \n\n";
cout << "CD Title: " << cd_name << '\n'; // print the title of the CD
cout << "Band/Singer: " << band << '\n' << '\n'; // print the band or singer name
}
else
{
cout << "The band or singer you typed in must not be very good\n";
cout << "we don't waste time with bad music.\n\n";
}
return 0;
}