Problems with declaration
I've written a program that sorts a list of 188 movies based on, title, year, media type and length. I am having problems with the creation of a menu though. It seems I cannot create a
working menu and here is the problem are of my code. The sort algorithms work but i cannot seem to pass the menu selection off the the int choice correctly. Can someone help me?
Code:
void selectionSort(const int, int, bool);
int main()
{
int choice;
string record;
int recordcount = 0;
ifstream dataIn;
//Open file
dataIn.open("Movies.dat");
if(dataIn.fail())
{
cout << "Unable to open the data file." << endl;
return 99;
}
//Read a record
getline(dataIn,record);
//location in the record of field separator (,)
int firstHalf = 0;
int i;
recordcount = 0;
while(dataIn.eof() == false)
{
if(record == "")
{
break;
}
i = record.find(',',0);
title[recordcount] = record.substr(0,i);
firstHalf = i+ 1;
i = record.find(',',i+1);
year[recordcount] = record.substr(firstHalf, i - firstHalf);
firstHalf = i+ 1;
i = record.find(',',i+1);
length[recordcount] = record.substr(firstHalf, i - firstHalf);
firstHalf = i+ 1;
i = record.find(',',i+1);
mediaType[recordcount] = record.substr(firstHalf, i - firstHalf);
recordcount++; //point to next element
getline(dataIn,record);
}
//Menu to select which type of sort
cout << "Which way would you like to see these movies sorted?" << endl;
cout << "A. By title. (via Bubble sort (Ascending)) " << endl;
cout << "B. By year.(via Bubble sort (Ascending))" << endl;
cout << "C. By media.(via Bubble sort (Ascending))" << endl;
cout << "D. By length.(via Bubble sort (Asending))" << endl;
cout << "E. By title. (via selection sort (Decending)) " << endl;
cout << "F. By year.(via selection sort (Decending))" << endl;
cout << "G. By media.(via selection sort (Decending))" << endl;
cout << "H. By length.(via selection sort (Decending))" << endl;
cout << "Enter your choice here:" << endl;
cin >> choice >> endl;
//Where we plug in choice
if (choice = A)
{
Sort(choice,188,true);
for (int i = 0; i < recordcount; i++)
{
if((i % 5) == 0)
{
cout << "Press [Enter] to continue";
cin.get();
}
cout << "title:"<<title[i]<<"\n";
cout << "year:"<<year[i]<<"\n";
cout << "media:"<<mediaType[i]<<"\n";
cout << "length:"<<length[i]<<"\n";
}
return 0;
}
}
}