// Number Sorter
#include <iostream>
usingnamespace std;
char menu()
{
char choice;
cout<< "\nNumber Sorter - Created By Ben Tickle";
cout<< "\n\n**************************************\n";
cout<< "\n\n Please choose one of the following:\n";
cout<< "\n\n 1 - Ascending order ";
cout<< "\n 2 - Descending order ";
cout<< "\n 3 - Exit";
cout<< "\n\n\n**************************************\n";
cout<< "\n\n Enter you choice and press return: ";
cin >> choice;
return choice;
}
int main()
{
int a[5];
char choice;
do
{
choice = menu();
switch (choice)
{
case'1':
cout << "\n\nAscending order"
<< "\n\n\nPlease enter 5 numbers include spaces:";
cin >> a[0];
cin >> a[1];
cin >> a[2];
cin >> a[3];
cin >> a[4];
void BubbleSort(apvector <int> &num)
{
int i, j, flag = 1; // set flag to 1 to start first pass
int temp; // holding variable
int numLength = num.length( );
for(i = 1; (i <= numLength) && flag; i++)
{
flag = 0;
for (j=0; j < (numLength -1); j++)
{
if (num[j+1] > num[j]) // ascending order simply changes to <
{
temp = num[j]; // swap elements
num[j] = num[j+1];
num[j+1] = temp;
flag = 1; // indicates that a swap occurred.
}
}
}
return; //arrays are passed to functions by address; nothing is returned
}
// Pause for user
system("pause");
break;
case'2':
cout<< "\n\nDescending order"
<< "\n\n\nPlease enter 5 numbers include spaces:";
// Pause for user
system("pause");
break;
case'3':
cout<< "Exit";
break;
default:
cout<< "\nNot a valid choice.";
}
} while (choice != '3');
return 0;
}
1. Move the function Bubble sort out of the main
2. I don't know what kind of parameters you want to use in Bubble sort but I guess is just a vector<int> &num
3. There is no such length property in vectors, you can use size
4. You are not including libraries
When you compile, any IDE gives you an output of the errors, there you can find why is not compiling, use that tool to correct your code ;)