This is a code which sorts arrays.

I use clock_t to determine the processing time for my code. However, it always stacks with the time taken from before. It looks like it's just adding the results.

Code:
int main(int argc, char *argv[])
{unsigned long n;//size of array -- long for big numbers of n
int choice, choice2, sort;//numbers corresponding to the choices(switch)
clock_t Begin, End;
float elapTicks, elapMilli;
wrongchoice://goto function -- bringing back to this point after entering wrong choice
cout<<"===============================
cout<<"\t\t\tChoose the order of the output:\n\t\t\t\t[1] Random-Descending\n\t\t\t\t[2] Ascending-Descending\n\t\t\t\t[3] Descending-Ascending\n\t\t\t\t[4] Random-Ascending\n\t\t\tChoice: ";
cin>>choice;
cout<<"\t\t\tIndicate size of array: ";
cin>>n;
long int array[n];//first and original array to be used all through the program
long int arrayb[n];//second/temporary array used to preserve/copy original values of first array
for (int i=0; i<n; i++)
{array[i]=rand()%99999;
arrayb[i]=array[i];//copy value of the first array into the second array
}
double temptime=0;
clock_t realend, realend2, realend3, realend4, realend5, realend6;
sorting:
cout<<"\n\t\t\t\t[1] Bubble Sort\n\t\t\t\t[2] Selection Sort\n\t\t\t\t[3] Insertion Sort\n\t\t\t\t[4] Quick Sort\n\t\t\t\t[5] Shell Sort\n\t\t\t\t[6] Merge Sort\n";
cout<<"\t\t\tChoose what sorting algorithm to use: ";
cin>>sort;
goto copyarray;//goto function to copy array elements(located at line 747)
sorting2://goto function -- used to resume back to this point after copying array elements
srand(time(NULL));
switch(choice)//first switch -- indicates the desired order of the output
{
case 1://Random-Descending
{cout<<"==============================
cout<<"\t\t\tUnsorted Array: "<<endl;
for(int i=0; i<n; i++)
cout<<array[i]<<"\t";
cout<<"\n\n\t\t\tSorted Array:\n";
switch(sort)//second swtich -- indicates what sorting algorithm to use
{
case 1:
{//Bubble Sort Descending
clock_t Begin1, End1;
realend=clock();
Begin1=clock();//indicates start of timer/clock counter(every start of cases for sorting)
BubbleSort2(array, n);//calling of function
End1=clock();//indicates end of timer/clock
float time1;
time1= (End1-Begin1/1000.00f);//used to convert value(taken from the clock code) to milliseconds(from seconds)
cout<<"Bubble Sort:"<<endl;
for (int i=0; i<n; i++)
cout<<array[i]<<"\t";
cout<<"\n\nTotal operational count is: "<<opcount<<endl;
cout<<"\nAlgorithm Runtime is: "<<time1<<" milliseconds.";
cout<<endl<<endl;
goto choose;//goto function to indicate what to do after sorting
break;}
case 2:
{//Selection Sort Descending
clock_t Begin2, End2;
realend2=clock();
Begin2=clock();
double temptime2=Begin2;
SelectionSort2(array, n);//calling of function
End2=clock();
float time2;
time2 = (End2-Begin2/1000.00f);
cout<<"Selection Sort:"<<endl;
for (int i=0; i<n; i++)
cout<<array[i]<<"\t";
cout<<"\n\nTotal operational count is: "<<opcount<<endl;
cout<<"\nAlgorithm Runtime is: "<<time2<<" milliseconds.";
cout<<endl<<endl;
goto choose;//goto function to indicate what to do after sorting
break;}
That is some part of my code. I couldn't put it all here since it's too long. The time adds up with the time that is first taken when I choose another option from the switch code, even though I declared a new variable for clock_t. Please help T_T I really don't know what's wrong with the code.

Here's the entire code:
http://www.daniweb.com/software-deve...48#post1775548



Feel free to paste it in any c++ debugger so you would understand the code better.

I hope someone can help me.