Can't Find Bug in basic MP3 Sorter
I'm writing this for a school project (yes I know it's messy, it's basicly fill in the blanks in the code the prof gave us). I have everything working but getting option 8 to work. It's supposed to reorder the index so it's in alphabetical order by title.
here's the code, maybe you could help me? I can't figure out why 8 isn't working.
Code:
#include <iostream.h>
#include <iomanip.h> // For setw()
#include <string.h> // For strcmp()
const int MAX_Songs = 3; // Maximum number of MP3s
int index = 0;
struct MP_Three
{
char Title [15];
char Artist[15];
char Genre[15];
};
int main()
{
MP_Three Collection[MAX_Songs]; // collection (Array) of MP3s
char CurrentTitle [15];
char CurrentArtist[15];
char CurrentGenre[15];
bool operator<(const MP_Three& a) {
//comparison operator...this allows you to sort MP_Three objects just like ints
return (strcmp(this->Title,a.Title) > 0);
}
int length = 0; // Number of entries
MP_Three CurrentSong; // Current record being entered
int op;
//Menu
while(op != 9)
{
cout << "*** choose an operation ***"<<endl;
cout << "1 Add a MP3 Collection"<<endl;
cout << "2 Search by Title"<<endl;
cout << "3 Search by Artist"<<endl;
cout << "4 View Entries" << endl;
cout << "5 Edit Entries" << endl;
cout << "6 Search by Genre" << endl;
cout << "7 Delete MP3" << endl;
cout << "8 Sort Entries (Not Completed)" << endl;
cout << "9 Quit"<< endl<<endl;
cin>>op;
cin.ignore(1,'\n');
//User Selections
if (op == 1) //Add an Mp3
{
index = 0;
while (index < MAX_Songs)
{
cout << "Enter the Title of MP3: ";
cin >> Collection[index].Title;
cout << "Enter the Artist: ";
cin >> Collection[index].Artist;
cout << "Enter the Genre: ";
cin >> Collection[index].Genre;
index++;
}
}
if (op == 2) //Search By Title
{
cout << "Enter Title: "<<endl;
cin >> CurrentTitle;
int found = 0;
int k;
for (k = 0; k < MAX_Songs; k++)
{
if (strcmp(CurrentTitle, Collection[k].Title) == 0)
{
index = k;
cout<<endl<<CurrentTitle<<" found at index "<< index<<endl<<endl;
cout<<"Title: "<<Collection[index].Title<<endl;
cout<<"Artist: "<<Collection[index].Artist<<endl;
cout<<"Genre: "<<Collection[index].Genre<<endl;
found = 1;
}
}
if (found == 0)
cout<<endl<< "MP3 record not found"<<endl<<endl;
}
if (op == 3) //SEARCH BY ARTIST
{
cout << "Enter Artist"<<endl;
cin >> CurrentArtist;
int found = 0;
int k;
for (k = 0; k < MAX_Songs; k++)
if (strcmp(CurrentArtist, Collection[k].Artist) == 0)
{
index = k;
cout<<endl<<CurrentArtist<<" found at index "<< index<<endl<<endl;
cout<<"Title: "<<Collection[index].Title<<endl;
cout<<"Artist: "<<Collection[index].Artist<<endl;
cout<<"Genre: "<<Collection[index].Genre<<endl;
found = 1;
}
}
if (op == 4) //View Entries
{
int i;
for (i = 0; i < MAX_Songs; i++)
{
cout << "Title: " << Collection[i].Title << endl;
cout << "Artist: " << Collection[i].Artist << endl;
cout << "Genre " <<Collection[i].Genre << endl << endl;
}
}
if (op == 5) //Edit Mp3 Info
{
cout << "Enter Title"<<endl;
cin >> CurrentTitle;
int found = 0;
int k;
for (k = 0; k < MAX_Songs; k++)
{
if (strcmp(CurrentTitle, Collection[k].Title) == 0)
{
index = k;
cout<<endl<<CurrentTitle<<" found at index "<< index<<endl<<endl;
cout<<"Title: "<<Collection[index].Title<<endl;
cout<<"Artist: "<<Collection[index].Artist<<endl;
cout<<"Genre: "<<Collection[index].Genre<<endl;
found = 1;
}
}
if (found == 0)
{
cout<<endl<< "MP3 record not found"<<endl<<endl;
}
cout << "Enter the new song Title of the MP3 ";
cin >> Collection[index].Title;
cout << "Enter the new Artist ";
cin >> Collection[index].Artist;
cout << "Enter the new Genre ";
cin >> Collection[index].Genre;
}
if (op == 6) //SEARCH BY GENRE
{
cout << "Enter Genre: "<<endl;
cin >> CurrentGenre;
int found = 0;
int k;
for (k = 0; k < MAX_Songs; k++)
if (strcmp(CurrentGenre, Collection[k].Genre) == 0)
{
index = k;
cout<<endl<<CurrentGenre<<" found at index "<< index<<endl<<endl;
cout<<"Title: "<<Collection[index].Title<<endl;
cout<<"Artist: "<<Collection[index].Artist<<endl;
cout<<"Genre: "<<Collection[index].Genre<<endl;
found = 1;
}
}
if (op ==7) //DELETE MP3
{
cout << "Enter Title"<<endl;
cin >> CurrentTitle;
int found = 0;
int k;
for (k = 0; k < MAX_Songs; k++)
{
if (strcmp(CurrentTitle, Collection[k].Title) == 0)
{
index = k;
cout<<endl<<CurrentTitle<<" found at index "<< index<<endl<<endl;
cout<<Collection[index].Title<<endl;
cout<<Collection[index].Artist<<endl;
cout<<Collection[index].Genre<<endl;
found = 1;
}
}
if (found == 0)
{
cout<<endl<< "MP3 record not found"<<endl<<endl;
}
cout << "Enter New Information to Delete Old MP3"<<endl;
cout << "Enter New Title: ";
cin >> Collection[index].Title;
cout << "Enter new Artist: ";
cin >> Collection[index].Artist;
cout << "Enter new Genre: ";
cin >> Collection[index].Genre;
}
if(opp ==8)
{
sort_array(Collection);
cout<< "Mp3s Sorted";
}
{
}
return 0;
}