Im supposed to sort a file in decending order using bubble sort into an array. My code does all of that but it repeats the sorted array 50 times instead of just listing it once. This is a C ++ file on Dev. Thanks for your help, it's due midnight haha.
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
const int NUMELEMENTS=50;
int main()
{
ifstream integer;
int Array[NUMELEMENTS];
int I;
integer.open("C://integer.txt", ios::in);
for (I = 0; I < NUMELEMENTS; I++)
{ integer >> Array[I] ;
{
int temp;
int flag =1;
for ( int i=1; i <= I && flag; i++ )
{
flag =0;
for ( int j=0; j < I - 1; j++ )
{
if ( Array[j+1] > Array[j] )
{
temp = Array[j];
Array[j] = Array[j + 1];
Array[j + 1] = temp;
flag =1;
}
}
}
for(temp=0; temp<I; temp++)
{cout << Array[temp] << endl;
}
}while (integer.eof());
}
system("PAUSE");
return 0;
}