here's my code can anyone tell me what is wrong with the sorting function
the infile and outfile???
the data file is 10 numbers like--
10.39
60.36
20.85
39.77
15.58
44.22
88.22
30.37
10.39
59.30
//this program uses the bubble sort to sort a numeric array
#include <iostream.h>
#include <fstream.h>
//function prototypes
void fillArray(float [10]);
void displayArray(float [10]);
void sortArray(short[10], float [10], short);
void writeToFile(float [10]);
void main()
{
//declare and initialize array
float number[10]={0};
//open file for input
ifstream infile;
infile.open("C:\\WINDOWS\\Desktop\\numbers.dat", ios::in);
ofstream outfile;
outfile.open("C:\\WINDOWS\\Desktop\\numbers.dat", ios:ut);
//verify that open was successful
if(!infile.fail()|| !outfile.fail())
{
//fill array with data from file
fillArray(number);
//display array
displayArray(number);
//sort array
sortArray(num,number,size);
//display sorted array
displayArray(number);
//write sorted information to a file
writeToFile(number);
}
else
cout << "Error opening file." << endl;
//end if (!inFile.fail())
} //end of main function
//*****programmer-defined function definitions*****
void fillArray(float number[])
{
for (short x=0;x<10;x=x+1)
{
infile>>number[x];
//infile.ignore(1);
}
infile.close();
} //end of fillArray function
void displayArray(float number[])
{
for(short d =0;d<10;d=d+1)
cout<<number[d]<<" ";
cout<<endl<<endl;
} //end of displayArray function
void sortArray(short num[],float number[],short size)
{
short maxsub =size-1;
short tempnumber =0;
char swap ='Y';
short lastswap = 0;
while (swap == 'Y')
{
swap ='N';
for (short a=0;a<maxsub;a=a+1)
{
if(num[a]>num[a+1])
{
swap ='Y';
tempnumber = num[a];
num[a]=num[a+1];
num[a+1]=tempnumber;
lastswap = a;
}
}
}
} //end of sortArray function
void writeToFile(float number[])
{
for (short y = 0; y < 10;y=y+1)
{
outfile <<number[y]<<endl;
}
outfile.close();
} //end of writeToFile function
Thanks for any help
the infile and outfile???
the data file is 10 numbers like--
10.39
60.36
20.85
39.77
15.58
44.22
88.22
30.37
10.39
59.30
//this program uses the bubble sort to sort a numeric array
#include <iostream.h>
#include <fstream.h>
//function prototypes
void fillArray(float [10]);
void displayArray(float [10]);
void sortArray(short[10], float [10], short);
void writeToFile(float [10]);
void main()
{
//declare and initialize array
float number[10]={0};
//open file for input
ifstream infile;
infile.open("C:\\WINDOWS\\Desktop\\numbers.dat", ios::in);
ofstream outfile;
outfile.open("C:\\WINDOWS\\Desktop\\numbers.dat", ios:ut);
//verify that open was successful
if(!infile.fail()|| !outfile.fail())
{
//fill array with data from file
fillArray(number);
//display array
displayArray(number);
//sort array
sortArray(num,number,size);
//display sorted array
displayArray(number);
//write sorted information to a file
writeToFile(number);
}
else
cout << "Error opening file." << endl;
//end if (!inFile.fail())
} //end of main function
//*****programmer-defined function definitions*****
void fillArray(float number[])
{
for (short x=0;x<10;x=x+1)
{
infile>>number[x];
//infile.ignore(1);
}
infile.close();
} //end of fillArray function
void displayArray(float number[])
{
for(short d =0;d<10;d=d+1)
cout<<number[d]<<" ";
cout<<endl<<endl;
} //end of displayArray function
void sortArray(short num[],float number[],short size)
{
short maxsub =size-1;
short tempnumber =0;
char swap ='Y';
short lastswap = 0;
while (swap == 'Y')
{
swap ='N';
for (short a=0;a<maxsub;a=a+1)
{
if(num[a]>num[a+1])
{
swap ='Y';
tempnumber = num[a];
num[a]=num[a+1];
num[a+1]=tempnumber;
lastswap = a;
}
}
}
} //end of sortArray function
void writeToFile(float number[])
{
for (short y = 0; y < 10;y=y+1)
{
outfile <<number[y]<<endl;
}
outfile.close();
} //end of writeToFile function
Thanks for any help